左侧 LinearLayout 内部的边框
Border on inside of LinearLayout on left side
如何在左侧的以下 LinearLayout 内部添加边框,使其 5dp
宽并适合 LinearLayout 的整个高度? LinearLayout 的高度是动态的,这意味着有时它可以 50dp
高,有时 60dp
高,等等
这是我当前的布局:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:background="@color/bg"
android:padding="15dp">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:textSize="14dp"
android:maxLines="2"
android:singleLine="false"
android:ellipsize="end"
/>
<TextView
android:id="@+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:textSize="10dp"
android:singleLine="true"
android:ellipsize="end"
/>
</LinearLayout>
谢谢。
好的。我以前不明白。
因此,要在可绘制文件夹中创建一个 xml 文件,其中包含以下内容。命名 xml
"layout_mainBG"
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="5dp" android:color="@android:color/background_dark" />
<solid android:color="#800000c0"/> </shape>
这符合您的需要。
如果你想要更复杂的东西
然后在 layout_main xml 文件的 <LinearLayout>
标签下添加此
android:baground = "@drawable/layout_mainBG
有关详细信息,请参阅此站点。即使是对话片段也一样
Create background of Popup Window with custom shape
如果你想要一侧只改变 layout_mainBG
到
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="@color/bg" />
</shape>
</item>
</layer-list>
这会给你一个黑色边框。
如何在左侧的以下 LinearLayout 内部添加边框,使其 5dp
宽并适合 LinearLayout 的整个高度? LinearLayout 的高度是动态的,这意味着有时它可以 50dp
高,有时 60dp
高,等等
这是我当前的布局:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:background="@color/bg"
android:padding="15dp">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:textSize="14dp"
android:maxLines="2"
android:singleLine="false"
android:ellipsize="end"
/>
<TextView
android:id="@+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:textSize="10dp"
android:singleLine="true"
android:ellipsize="end"
/>
</LinearLayout>
谢谢。
好的。我以前不明白。
因此,要在可绘制文件夹中创建一个 xml 文件,其中包含以下内容。命名 xml "layout_mainBG"
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="5dp" android:color="@android:color/background_dark" />
<solid android:color="#800000c0"/> </shape>
这符合您的需要。
如果你想要更复杂的东西
然后在 layout_main xml 文件的 <LinearLayout>
标签下添加此
android:baground = "@drawable/layout_mainBG
有关详细信息,请参阅此站点。即使是对话片段也一样
Create background of Popup Window with custom shape
如果你想要一侧只改变 layout_mainBG 到
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="@color/bg" />
</shape>
</item>
</layer-list>
这会给你一个黑色边框。