我正在尝试将分隔线添加到水平线性布局,但无处可去。分隔线只是没有显示。我是 Android 的新手。
这是我的布局 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/llTopBar"
android:orientation="horizontal"
android:divider="#00ff00"
android:dividerPadding="22dip"
android:showDividers="middle">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="asdf" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="asdf" />
</LinearLayout>
</RelativeLayout>
最佳答案
将其用于水平分隔符
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/honeycombish_blue" />
这是垂直分隔线
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/honeycombish_blue" />
或者如果你可以使用 LinearLayout 分隔线,作为水平分隔线
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:height="1dp"/>
<solid android:color="#f6f6f6"/>
</shape>
在线性布局中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/divider"
android:orientation="vertical"
android:showDividers="middle" >
如果你想使用垂直分隔线,那么在形状中使用 android:width="1dp"
android:height="1dp"
提示:不要忘记 android:showDividers
项。
关于android - 如何将(垂直)分隔线添加到水平 LinearLayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15128652/