垂直线性布局的分隔符?

10

我正在尝试使用XML中的android:divider属性在LinearLayout的视图之间放置分隔符。当我使用垂直LinearLayout时,没有显示分隔符。当我使用水平LinearLayout时,分隔符显示并正常工作。这是我用作分隔符的可绘制对象(drawable/one.xml):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:width="1dip" />
    <solid android:color="#FFFFFF" />
</shape>

这是我的LinearLayout布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:divider="@drawable/one"
              android:dividerPadding="10dp"
              android:showDividers="middle">
<TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="test1"
            />

<TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="test2"
            />

</LinearLayout>

在垂直线性布局中无法使用divider属性吗,还是我遗漏了什么?

1个回答

26

对于垂直布局,在drawable中,我认为您需要替换

  <size android:width="1dip" />
  <size android:height="1dip" />

1
或者说,你需要有两个可绘制对象,一个将宽度设置为1dip,另一个将高度设置为1dip。 - scrayne
1
你救了我一命 ;) - marioosh
该死,这应该很明显。谢谢你提醒我。 - LiveMynd

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