如何在android中用一行分隔版面的页脚

如何在android中用一行分隔版面的页脚,android,android-layout,footer,separator,Android,Android Layout,Footer,Separator,我正在构建一个包含线性布局和众多元素的页面。在屏幕底部,我想添加一行,分隔“页脚”。如何做到这一点?我一直在考虑作为一个文本视图的东西,并将行添加到文本中,但我确信有更好的方法来完成。谢谢 将此xml用于您的目的。。。。。。这只是一个例子 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro

我正在构建一个包含线性布局和众多元素的页面。在屏幕底部,我想添加一行,分隔“页脚”。如何做到这一点?我一直在考虑作为一个文本视图的东西,并将行添加到文本中,但我确信有更好的方法来完成。谢谢

将此xml用于您的目的。。。。。。这只是一个例子

<?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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5">

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!" />

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Footer" />

    </LinearLayout>


</LinearLayout>

注意:-第二个线性布局用于主要内容。。。。页脚的第三个线性布局…

上述xml的输出


将此xml用于您的目的。。。。。。这只是一个例子

<?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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5">

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!" />

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Footer" />

    </LinearLayout>


</LinearLayout>

注意:-第二个线性布局用于主要内容。。。。页脚的第三个线性布局…

上述xml的输出


要从容器中分离
页脚
,可以添加
作为分隔符。但是我可以提供更好的方法,您必须将
阴影添加到
线性布局中
,这样可以将主容器和页脚分开

我的方法

footer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@drawable/linearlayout_upper_shadow"
    android:layout_alignParentBottom="true">
    <LinearLayout
        android:id="@+id/below_linear_layout"
        android:layout_width="0.0dp"
        android:layout_height="match_parent"
        android:layout_weight="50.0"
        android:orientation="vertical"
        android:weightSum="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0.0dp"
            android:layout_marginLeft="@dimen/normal_margin15"
            android:layout_marginTop="@dimen/normal_margin5"
            android:layout_weight="0.50"
            android:text="$1,605"
            android:textSize="@dimen/textsize20"
            android:textColor="@color/black1" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0.0dp"
            android:layout_marginLeft="@dimen/normal_margin15"
            android:layout_weight="0.50"
            android:text="View price detail"
            android:textColor="@color/colorPrimary"
            android:textSize="@dimen/textsize13"
            android:layout_marginTop="-5dp" />
    </LinearLayout>
    <Button
        android:id="@+id/continue_button"
        android:layout_width="0.0dip"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/normal_margin8"
        android:layout_weight="50.0"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:text="@string/continue_string"
        android:textColor="@color/white1"
        android:textSize="@dimen/textsize13" />
</LinearLayout>
<?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="@color/linear_layout_shadow"/>
      />
    </shape>
  </item>

  <item
      android:left="0dp"
      android:right="0dp"
      android:top="1dp"
      android:bottom="0dp">
    <shape android:shape="rectangle">
      <solid android:color="@android:color/white"/>
      <corners android:radius="2dp" />
    </shape>
  </item>
</layer-list>

用于分离器

separator.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@drawable/linearlayout_upper_shadow"
    android:layout_alignParentBottom="true">
    <LinearLayout
        android:id="@+id/below_linear_layout"
        android:layout_width="0.0dp"
        android:layout_height="match_parent"
        android:layout_weight="50.0"
        android:orientation="vertical"
        android:weightSum="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0.0dp"
            android:layout_marginLeft="@dimen/normal_margin15"
            android:layout_marginTop="@dimen/normal_margin5"
            android:layout_weight="0.50"
            android:text="$1,605"
            android:textSize="@dimen/textsize20"
            android:textColor="@color/black1" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0.0dp"
            android:layout_marginLeft="@dimen/normal_margin15"
            android:layout_weight="0.50"
            android:text="View price detail"
            android:textColor="@color/colorPrimary"
            android:textSize="@dimen/textsize13"
            android:layout_marginTop="-5dp" />
    </LinearLayout>
    <Button
        android:id="@+id/continue_button"
        android:layout_width="0.0dip"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/normal_margin8"
        android:layout_weight="50.0"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:text="@string/continue_string"
        android:textColor="@color/white1"
        android:textSize="@dimen/textsize13" />
</LinearLayout>
<?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="@color/linear_layout_shadow"/>
      />
    </shape>
  </item>

  <item
      android:left="0dp"
      android:right="0dp"
      android:top="1dp"
      android:bottom="0dp">
    <shape android:shape="rectangle">
      <solid android:color="@android:color/white"/>
      <corners android:radius="2dp" />
    </shape>
  </item>
</layer-list>

/>
输出:


要从容器中分离
页脚
,可以添加
作为分隔符。但是我可以提供更好的方法,您必须将
阴影添加到
线性布局中
,这样可以将主容器和页脚分开

我的方法

footer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@drawable/linearlayout_upper_shadow"
    android:layout_alignParentBottom="true">
    <LinearLayout
        android:id="@+id/below_linear_layout"
        android:layout_width="0.0dp"
        android:layout_height="match_parent"
        android:layout_weight="50.0"
        android:orientation="vertical"
        android:weightSum="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0.0dp"
            android:layout_marginLeft="@dimen/normal_margin15"
            android:layout_marginTop="@dimen/normal_margin5"
            android:layout_weight="0.50"
            android:text="$1,605"
            android:textSize="@dimen/textsize20"
            android:textColor="@color/black1" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0.0dp"
            android:layout_marginLeft="@dimen/normal_margin15"
            android:layout_weight="0.50"
            android:text="View price detail"
            android:textColor="@color/colorPrimary"
            android:textSize="@dimen/textsize13"
            android:layout_marginTop="-5dp" />
    </LinearLayout>
    <Button
        android:id="@+id/continue_button"
        android:layout_width="0.0dip"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/normal_margin8"
        android:layout_weight="50.0"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:text="@string/continue_string"
        android:textColor="@color/white1"
        android:textSize="@dimen/textsize13" />
</LinearLayout>
<?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="@color/linear_layout_shadow"/>
      />
    </shape>
  </item>

  <item
      android:left="0dp"
      android:right="0dp"
      android:top="1dp"
      android:bottom="0dp">
    <shape android:shape="rectangle">
      <solid android:color="@android:color/white"/>
      <corners android:radius="2dp" />
    </shape>
  </item>
</layer-list>

用于分离器

separator.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@drawable/linearlayout_upper_shadow"
    android:layout_alignParentBottom="true">
    <LinearLayout
        android:id="@+id/below_linear_layout"
        android:layout_width="0.0dp"
        android:layout_height="match_parent"
        android:layout_weight="50.0"
        android:orientation="vertical"
        android:weightSum="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0.0dp"
            android:layout_marginLeft="@dimen/normal_margin15"
            android:layout_marginTop="@dimen/normal_margin5"
            android:layout_weight="0.50"
            android:text="$1,605"
            android:textSize="@dimen/textsize20"
            android:textColor="@color/black1" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="0.0dp"
            android:layout_marginLeft="@dimen/normal_margin15"
            android:layout_weight="0.50"
            android:text="View price detail"
            android:textColor="@color/colorPrimary"
            android:textSize="@dimen/textsize13"
            android:layout_marginTop="-5dp" />
    </LinearLayout>
    <Button
        android:id="@+id/continue_button"
        android:layout_width="0.0dip"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/normal_margin8"
        android:layout_weight="50.0"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:text="@string/continue_string"
        android:textColor="@color/white1"
        android:textSize="@dimen/textsize13" />
</LinearLayout>
<?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="@color/linear_layout_shadow"/>
      />
    </shape>
  </item>

  <item
      android:left="0dp"
      android:right="0dp"
      android:top="1dp"
      android:bottom="0dp">
    <shape android:shape="rectangle">
      <solid android:color="@android:color/white"/>
      <corners android:radius="2dp" />
    </shape>
  </item>
</layer-list>

/>
输出:


只需将具有指定背景的视图添加到xml布局中,如下所示:

<View
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="@android:color/darker_gray"/>

只需将具有指定背景的视图添加到xml布局中,如下所示:

<View
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="@android:color/darker_gray"/>


发布您的xml文件,这样人们就可以帮助您了。好吧,我想知道到底要发布什么,否则没问题。它不在xml中,我只是在布局。或者我可能需要添加一个xml并在那里指定设备?使用下面的回答您在xml文件中获得了一些想法,因此人们可以帮助您。好吧,我想知道到底要发布什么,否则没有问题。它不在xml中,我只是在布局。或者我可能需要添加一个xml并在那里指定设备?使用下面的答案你有一些想法吗?你,它与添加视图一起工作,我忘记了它的存在:))谢谢你,它与添加视图一起工作,我忘记了它的存在:))