[英]Android Layout: How to add bottom and right border into linear layout together?
我有以下线性布局,用作表格单元格。 我想添加选定的模板右下边框。 但是现在我只能在右侧添加边框。
如何一次向选定边添加边框?
非常感谢任何建议。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="60dp"
android:layout_height="80dp"
android:gravity="right"
android:background="@color/white"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal|center"
android:gravity="center_horizontal|center"
android:layout_marginRight="10dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/variable_type_first_column"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/heart"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center"/>
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Weight"
android:layout_below="@id/variable_type_first_column"
android:layout_gravity="center_horizontal|bottom"
android:gravity="center_horizontal|bottom"
android:textColor="@color/app_blue"
android:textAlignment="center"
android:textSize="12sp"/>
</LinearLayout>
<View
android:layout_width="1.5dip"
android:layout_height="match_parent"
android:layout_gravity="right"
android:foregroundGravity="right"
android:background="@drawable/separator_table_header_first" />
</LinearLayout>
在drawable文件夹中创建可绘制文件。
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="5dp"
android:insetLeft="-7dp"
android:insetRight="5dp"
android:insetTop="-7dp">
<shape android:shape="rectangle">
<stroke
android:width="5dp"
android:color="#ff0000" />
<solid android:color="#00000000" />
</shape>
</inset>
并将其设置为线性布局的背景。
最简单的方法是将LinearLayout包装在FrameLayout中:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="60dp"
android:layout_height="80dp"
android:gravity="right"
android:background="@color/white"
>
<LinearLayout
...
Your layout without the divider Views
...
</LinearLayout>
<View
android:layout_width="1.5dip"
android:layout_height="match_parent"
android:layout_gravity="right"
android:foregroundGravity="right"
android:background="@drawable/separator_table_header_first"
/>
<View
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_gravity="bottom"
android:foregroundGravity="bottom"
android:background="@drawable/separator_table_header_first"
/>
</FrameLayout>
您可以使用RelativeLayouts设计更平坦的XML,虽然这可能更有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.