我在GroupView的ExpandableListView中设置TextView的宽度时遇到问题。此ExpandableListView位于滑动菜单中。 菜单第一次滑动时,GroupView如下所示:
但是当我们点击一些选项时,它看起来像这样:
这是正确的观点,我每次都喜欢这种观点,而不仅仅是当我们点击某些群体选项时。我该如何修复这个错误?
这是我的源代码:
activity_main.xml中
<ExpandableListView
android:fillViewport="true"
android:padding="20dp"
android:id="@+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:groupIndicator="@null"
android:choiceMode = "singleChoice"
android:dividerHeight="10dp"
android:divider="@color/blue"
android:childDivider="@color/blue"
android:background="@color/blue"
android:layout_gravity="center_horizontal|center_vertical"
/>
expandable_list_group.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:id="@+id/ll"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
android:fillViewport="true"
android:gravity="center_horizontal|center_vertical"
>
<TextView
android:fillViewport="true"
android:background="@drawable/expandable_list_item_background"
android:id="@+id/lblListHeader"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="17dp"
android:textColor="@drawable/list_item_text_selector"
android:gravity="center_horizontal|center_vertical"
/>
</LinearLayout>
expandable_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
android:gravity="center_horizontal|center_vertical"
>
<TextView
android:background="@drawable/button_shape"
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="17dp"
android:textColor="@drawable/list_item_text_selector"
android:gravity="center_horizontal|center_vertical"
/>
</LinearLayout>
MainLayout.java(设置幻灯片菜单宽度的方法)
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mainLayoutWidth = MeasureSpec.getSize(widthMeasureSpec);
menuRightMargin = mainLayoutWidth * 20 / 100;
}