繁体   English   中英

如何在顶部和底部设置边框线性布局

[英]how to set border linear layout on top and bottom

<?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>

这是我的代码我试图在Linarlayout上显示边框顶部和底部,但我无法显示效果我必须设置主页线性布局和办公室线性布局的边框顶部和底部我试图设置,但效果不会来请检查我在哪里做错了。

<?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添加到drawable文件夹中,并将此drawable作为布局的背景。

希望这可以帮助。

这可以使用LayerList完成

创建一个可绘制的名称border_top_bottom.xml

<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>

在LinearLayout背景属性上使用

andorid:background:"@drawable/border_top_bottom.xml"

使用以下代码在drawable中添加xml,然后将此xml指定为线性布局背景

<?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>

我认为你的问题不是你的形状,而是你在布局中引用它的方式:

         <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" >

您已设置对anim文件夹的引用,但它必须位于drawable文件夹中。 如果您的形状在anim文件夹中,请将其放入drawable文件夹并更正您的LinearLayouts src属性:

       android:src="@drawable/linearsavelocationbackground"

然后,如果这不是您想要的,请使用krunal和EagleEye中的示例创建一个形状。

@Edge请使用此代码让我们说xml文件linearbg.xml的名称,并将其放在资源下的drawable文件夹中。

 <?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>

现在使用此linearbg.xml作为线性布局中的背景,如android:background =“@ drawable / linearbg”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM