我想在布局的中间画一条线,并使用它作为其他项目的分隔符,如TextView。有没有一个好的小部件。我真的不想使用图像,因为它很难匹配其他组件到它。我也想让它有相对的位置。谢谢
当前回答
就这样写:
android:divider="?android:dividerHorizontal"
android:showDividers="middle"
完整的例子:
<LinearLayout
android:id="@+id/llTipInformation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvServiceRating"
android:orientation="horizontal"
android:divider="?android:dividerHorizontal"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:showDividers="middle">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/main.msg.tippercent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/colorWhite"
android:layout_marginTop="@dimen/activity_vertical_margin"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/main.msg.tiptotal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/colorWhite"
android:layout_marginTop="@dimen/activity_vertical_margin"/>
</LinearLayout>
其他回答
将此添加到你想要分隔符的布局中(修改属性以适应你的需要):
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@android:drawable/divider_horizontal_dark"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="2dp"
android:paddingTop="2dp" />
这很简单。只需要创建一个背景颜色为黑色的视图。
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000"/>
这将创建一个具有背景色的水平线。您还可以添加其他属性,如边距,填充等,就像任何其他视图。
你可以在第一个TextView之后使用<View>元素。
<View
android:layout_marginTop="@dimen/d10dp"
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#c0c0c0"/>
添加一条水平的黑线:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/line"
style="?android:attr/listSeparatorTextViewStyle"
android:paddingTop="5dip"
android:gravity="center_horizontal"
android:layout_below="@+id/connect_help"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000" />
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在Android Studio中创建aar文件