Android 在ExpandableListView的子视图布局中添加textview
我有expandableListview,它工作得很好,但现在在childview中,我必须使它更大,并添加更多的信息,从某种意义上说,我需要为每个孩子添加更多的文本视图。例如,子视图的布局应该如下所示Android 在ExpandableListView的子视图布局中添加textview,android,android-layout,expandablelistview,baseadapter,Android,Android Layout,Expandablelistview,Baseadapter,我有expandableListview,它工作得很好,但现在在childview中,我必须使它更大,并添加更多的信息,从某种意义上说,我需要为每个孩子添加更多的文本视图。例如,子视图的布局应该如下所示 Type 1 Value1 Type 2 Value2 Type 3 Value3 Category Average 我已经有了这个类别和平均值,但现在需要子类型和相应的值 为了实现这一点,我尝试膨胀新的布局有两个文本视图,然后添加到子视图。但这
Type 1 Value1
Type 2 Value2
Type 3 Value3
Category Average
我已经有了这个类别和平均值,但现在需要子类型和相应的值
为了实现这一点,我尝试膨胀新的布局有两个文本视图,然后添加到子视图。但这是重叠的信息,我不知道如何使它垂直。
我正在分享一段代码,它正试图做到这一点
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
holder = new ViewHolder();
if (convertView == null)
{
holder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.list_item, null);
holder.sub_rl = (RelativeLayout) convertView.findViewById(R.id.sub_row_layout);
holder.cat = (TextView) convertView.findViewById(R.id.sub_row_cat);
holder.avg = (TextView) convertView.findViewById(R.id.sub_row_avg);
convertView.setTag(R.id.sub_row_layout, holder.sub_rl);
convertView.setTag(R.id.sub_row_cat, holder.cat);
convertView.setTag(R.id.sub_row_avg, holder.avg);
convertView.setTag(holder);
}
else
if (getChild(groupPosition, childPosition).type.equals("Emp")) {
for(int i = 0; i < 5; i ++){
Log.d(TAG, "coming ");
LayoutInflater inflater2 = null;
inflater2 = (LayoutInflater) mContext.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mLinearView2 = inflater2.inflate(R.layout.type_layout, null);
LinearLayout wifi_layout = (LinearLayout) mLinearView2.findViewById(R.id.type_layout);
TextView mSubItemName = (TextView) mLinearView2.findViewById(R.id.row_type);
TextView sub_value = (TextView) mLinearView2.findViewById(R.id.row_value);
mSubItemName.setText("Sub Text "+ i);
holder.sub_rl.addView(wifi_layout);
}
if (getChild(groupPosition, childPosition).cat.isEmpty()) {
if (getChild(groupPosition, childPosition).cat != null && holder.cat != null)
holder.cat.setText("(Hidden Category)");
} else {
if (getChild(groupPosition, childPosition).cat != null && holder.cat != null)
holder.cat.setText(getChild(groupPosition, childPosition).cat);
}
if (getChild(groupPosition, childPosition).avg != null && holder.avg != null)
holder.avg.setText(getChild(groupPosition, childPosition).avg);
return convertView;
}
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:id="@+id/es_child_main"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/sub_row_layout"
android:layout_width="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/sub_row_cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_marginTop="8dp"
android:textColor="#ffffff"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="@+id/sub_row_avg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sub_row_cat"
android:textSize="15dp"
android:textColor="#ffffff"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"/>
</RelativeLayout>
</RelativeLayout>
任何建议都会很好…或更好的方法谢谢我建议使用线性布局或更好的表格布局,因为您需要这样的子布局,它适合我:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type 1" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Value 1" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type 2" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Value 2" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type 3" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Value 3" />
</TableRow>
</TableLayout>
post your list_item.xml code更新了问题mbut我不明白你的意思,为什么我应该使用表布局作为我的主布局,即list_item?\要获得结果,请在“例如,子视图的布局应该是这样的”行下方发布。如果我没有错的话,你想在单子视图中显示三行,对吗?