Android 如何在顶部和底部设置边框线性布局
边境地带Android 如何在顶部和底部设置边框线性布局,android,Android,边境地带 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" androi
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/home"
android:layout_width="match_parent"
android:layout_height="60dip"
android:layout_marginRight="5dip"
android:src="@anim/linearsavelocationbackground"
android:weightSum="1" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_marginTop="15dip"
android:layout_weight=".2"
android:src="@drawable/homestatus" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:layout_weight=".6"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Home"
android:textColor="#3a3838"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/homeimage"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_marginRight="5dip"
android:layout_marginTop="15dp"
android:layout_weight="0.20"
android:src="@drawable/deletingright" />
</LinearLayout>
<LinearLayout
android:id="@+id/office"
android:layout_width="match_parent"
android:layout_height="60dip"
android:layout_marginRight="5dip"
android:background="#ffffff"
android:src="@anim/linearsavelocationbackground"
android:weightSum="1" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_marginTop="15dip"
android:layout_weight=".2"
android:src="@drawable/work" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:layout_weight=".6"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Home"
android:textColor="#3a3838"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/homeimage"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_marginRight="5dip"
android:layout_marginTop="15dp"
android:layout_weight="0.20"
android:src="@drawable/deletingright" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
这是我的代码我试图在直线布局上显示边框顶部和底部,但我无法显示效果我必须设置家庭线性布局和办公室线性布局的顶部和底部边框我试图设置,但效果不好请检查哪里出错。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<solid android:color="#CCCCCC"/>
</shape>
使用上述布局作为背景边框。它会给你一个很好的效果。如果愿意,请更改颜色和填充。将其作为xml添加到可绘制文件夹中,并将其作为布局的背景进行绘制
希望这能有所帮助。使用以下代码在绘图表中添加xml,然后将此xml指定为线性布局背景
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="1dp">
<shape android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="@android:color/darker_gray" />
<solid android:color="@android:color/transparent" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
我认为你的问题不在于你的形状,而在于你如何在布局中引用它:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#FF000000" />
<solid android:color="#FFDDDDDD" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#000" />
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
然后,如果这不是您想要的,请使用krunal和EagleEye的示例创建一个形状。@Edge请使用此代码
假设xml文件的名称为linearbg.xml,并将其放在参考资料下的drawable文件夹中
android:src="@drawable/linearsavelocationbackground"
现在在线性布局中使用这个linearbg.xml作为背景
android:background=“@drawable/linearbg”。这可以使用层列表完成 创建可绘制名称
border\u top\u bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#EEEEEE" />
</shape>
</item>
<!-- This is the line -->
<item
android:top="1dp"
android:bottom="1dp">
<shape>
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
为什么要将其设置在动画文件夹中?它必须是可绘制文件夹中的一个可绘制文件…检查效果不出现我调用了相同的东西你是如何使用它的?它给了我意想不到的文件结尾它现在工作,但在底部它不出现这里是我的整个Xml,我试着在两个线性布局中设置它像这样出现Xml:Image:像这样出现,而我想如果在线性布局上没有设置方向,请执行此操作并检查结果。。。。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#EEEEEE" />
</shape>
</item>
<!-- This is the line -->
<item
android:top="1dp"
android:bottom="1dp">
<shape>
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/your_border_color" />
</shape>
</item>
<item
android:top="1dp"
android:bottom="1dp">
<shape android:shape="rectangle" >
<solid android:color="@color/your_fill_color" />
</shape>
</item>
andorid:background:"@drawable/border_top_bottom.xml"