Android布局:如何将底部和右侧边框一起添加到线性布局中?
我有下面的线性布局,它被用作表格单元。我想添加到选定的模板的右边框和下边框。但现在我只能在右边添加边框了 如何一次将边框添加到选定的边 非常感谢你的建议Android布局:如何将底部和右侧边框一起添加到线性布局中?,android,android-layout,styling,border-layout,Android,Android Layout,Styling,Border Layout,我有下面的线性布局,它被用作表格单元。我想添加到选定的模板的右边框和下边框。但现在我只能在右边添加边框了 如何一次将边框添加到选定的边 非常感谢你的建议 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="60dp" android:layout_h
<?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>
最简单的方法是将线性布局包装到框架布局中:
<?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>
在可绘制文件夹中创建可绘制文件
<?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>
并将其设置为线性布局的背景