【发布时间】:2018-07-23 21:07:14
【问题描述】:
我必须创建一个类似于图片中的界面但我不知道如何在linearlayouts之间添加一条线
【问题讨论】:
我必须创建一个类似于图片中的界面但我不知道如何在linearlayouts之间添加一条线
【问题讨论】:
自行调整
<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>
【讨论】:
你可以通过创建一个布局比如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>
【讨论】: