【问题标题】:How to divide a layout by a real line in android?如何在android中用实线划分布局?
【发布时间】:2018-07-23 21:07:14
【问题描述】:

我必须创建一个类似于图片中的界面但我不知道如何在linearlayouts之间添加一条线

【问题讨论】:

标签: android android-layout


【解决方案1】:

自行调整

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

            <View
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_weight="1.5"
                android:background="@color/Black"></View>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:src="@drawable/ic_clock"/>
            <View
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_weight="1.5"
                android:background="@color/Black"></View>

        </LinearLayout>

【讨论】:

    【解决方案2】:

    你可以通过创建一个布局比如RelativeLayout并将高度设置为1dp并用你想要的线条颜色填充背景来创建线条:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/black">
    
    </RelativeLayout>
    

    这只是创建线条的一种方法,还有其他方法,例如创建自定义资源背景。

    另一个中间有断点的例子(设置中心布局的颜色以匹配屏幕的背景颜色):

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:orientation="horizontal">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/black">
    
        </RelativeLayout>
    
        <RelativeLayout
            android:layout_width="100dp"
            android:layout_height="1dp"
            android:background="@android:color/white">
    
        </RelativeLayout>
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/black">
    
        </RelativeLayout>
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 2016-12-02
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多