我想用填充更改ExpandableListView组指示器.
我使用自定义适配器将数据加载到ExpandableListView.
这是我的ExpandableListView xml.
<ExpandableListView android:id="@+id/Ex_offers" android:layout_width="250dp" android:layout_height="400dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:childDivider="#00000000" android:groupIndicator="@drawable/settings_selector" android:listSelector="@android:color/transparent"> </ExpandableListView>
这是GroupView xml
<TextView android:id="@+id/lblListHeadertwo" android:layout_width="match_parent" android:layout_height="40dp" android:background="@drawable/transperant_bar" android:fontFamily="Lato" android:paddingLeft="15dp" android:textColor="#daac56" android:textStyle="bold" android:textSize="17sp" android:paddingTop="8dp" />
这是ChildView xml
<TextView android:id="@+id/text_offers" android:layout_width="300dp" android:layout_height="20dp" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:background="@drawable/transperant_bar" android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" android:textColor="#daac56" android:textSize="14sp"/> <ImageView android:id="@+id/img" android:layout_width="15dp" android:layout_height="15dp" android:layout_marginLeft="12dp"/>
这是输出图像,我想为此指标设置保证金.
解决方法
setIndicatorBounds(int,int)对Android 4.3无效.
他们引入了一个新方法setIndicatorBoundsRelative(int,int),它适用于4.3.
他们引入了一个新方法setIndicatorBoundsRelative(int,int),它适用于4.3.
public int GetPixelFromDips(float pixels) { // Get the screen's density scale final float scale = getResources().getDisplayMetrics().density; // Convert the dps to pixels,based on density scale return (int) (pixels * scale + 0.5f); } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int width = metrics.widthPixels; if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { explvList.setIndicatorBounds(width-GetPixelFromDips(35),width-GetPixelFromDips(5)); } else { explvList.setIndicatorBoundsRelative(width-GetPixelFromDips(35),width-GetPixelFromDips(5)); } }