1
当我扩展我的可扩展列表中的子布局时,它每次形成不同。我使用的具有权重的线性布局属性,所以我不认为这应该发生Android扩展列表子版面布局不正确?
没有额外的代码也存在于getChildView()
: -
@Override
public View getChildView(int groupPosition, int childPosition, boolean b, View convertView, ViewGroup viewGroup) {
LayoutInflater cInflator = context.getLayoutInflater();
if (convertView == null) {
convertView = cInflator.inflate(R.layout.childrow, null);
}
return convertView;
}
childrow.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_headings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_headings_gradient"
android:padding="10dp" >
<TextView
android:id="@+id/user_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_weight="40"
android:textColor="@color/manage_users_heading_grey"
android:textSize="15sp"
android:textStyle="bold" />
<View
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="30" />
<TextView
android:id="@+id/block"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:gravity="center"
android:maxWidth="120dp"
android:text="BLOCK"
android:textColor="@color/red"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/activities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="30"
android:gravity="center"
android:text="RESET PASSWORD"
android:textColor="@color/manage_users_reset_pass"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
图片1: - 正确的扩大布局=首次展开: -
图2: - 不正确的扩展布局=第二次扩展: -
当你使用'layout_weight'不使用'layout_width = “WRAP_CONTENT”'。使用'0dp'替代。此外,你应该像这样夸大你的布局:'cInflator.inflate(R.layout.childrow,viewGroup,false);' – Lovis
@DonL。你的评论看起来像一个答案 – gunar
@ gunar好,这是一个普遍的提示。但你可能是对的。 – Lovis