如何制作带有默认展开/折叠图标指示器的可扩展列表视图?

3

我正在开发一个带有设计的安卓应用。

http://prntscr.com/86wnmm

这里是可扩展列表默认的图标指示器,显示在左侧。如何将该图标指示器显示在列表视图的右侧?是否可以通过更改XML文件来实现此操作?

我的XML代码如下:

`

<ExpandableListView
    android:id="@+id/expandableListView"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:indicatorRight="?android:attr/expandableListPreferredItemIndicatorRight"
    android:dividerHeight="0.7dp" />

`


尝试使用http://developer.android.com/reference/android/widget/ExpandableListView.html#attr_android:indicatorRight - Bhargav
5个回答

10

操作非常简单,只需按照以下两个步骤:

1.) 只需要在你的ExpandableListView xml文件中添加这一行。

          android:layoutDirection="rtl"

2.) 然后,在您的list item.xml文件中,或者无论您将其命名为什么,请放置这两行代码...

    android:gravity="left"
    android:layoutDirection="ltr"

这就是你所需要的,演出结束啦!只需运行它即可...:)


0

对于所有设备的有效解决方案是获取可展开列表的宽度并将指示器边界设置为右侧。

在包含可展开列表视图的 Activity 中覆盖以下方法。

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mExpandableListView.setIndicatorBounds(mExpandableListView.getRight()- 40, mExpandableListView.getWidth());
} 

这肯定会很有帮助。


0
使用下面的重写方法与setIndicatorBoundsRelative方法一起使用,对于低于gellybean版本的情况下使用setIndicatorBounds方法可以解决该问题。
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
      mExpandableListView.setIndicatorBoundsRelative(mExpandableListView.getRight()- 40, mExpandableListView.getWidth());

}

0
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        expandableListView.setIndicatorBounds(expandableListView.getWidth()-40,expandableListView.getWidth());
    } else {
        expandableListView.setIndicatorBoundsRelative(expandableListView.getWidth()-40,expandableListView.getWidth());
    }
}

-2

<ExpandableListView/>标签中的android:indicatorLeft


添加一些解释 - Jaiprakash Soni
这类似于添加左边距,但只将指示器向右移动:)试试看,让我知道。 - androidbear

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接