AndroidにおけるTextViewとExpandableListViewとScrollViewのスライド競合の解決
2316 ワード
Androidにはスライドのコントロールがたくさんありますが、彼らの間にはスライドの衝突の問題があります.
次に、ListViewとExpandableListViewの2つの方法をお勧めします.
の競合の問題:
1、ListViewとScrolViewの衝突問題
2、ExpandableListViewとScrollViewの問題;
このコントロールは2階建てのドロップダウンボックスに設計されています.これにはツールクラスが必要です.このツールクラスをjavaパッケージにつける必要があります.
XMLレイアウト:
これでスライド衝突の問題が解決します
次に、ListViewとExpandableListViewの2つの方法をお勧めします.
の競合の問題:
1、ListViewとScrolViewの衝突問題
public void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
上記の方法をクラスに貼り付け、アダプタを追加した次のように書きます. listView.setAdapter(adapter2);
setListViewHeightBasedOnChildren(lv);
2、ExpandableListViewとScrollViewの問題;
このコントロールは2階建てのドロップダウンボックスに設計されています.これにはツールクラスが必要です.このツールクラスをjavaパッケージにつける必要があります.
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ExpandableListView;
public class MyExpandableListView extends ExpandableListView {
public MyExpandableListView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyExpandableListView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
XMLレイアウト:
これでスライド衝突の問題が解決します