Android-如何在linearlayouts之间生成线条
我正在尝试使用XML生成一个如下所示的UI 蓝色勾号按钮和文本视图与垂直放置的LinearLayout对齐,因此在相对布局中总共有3个LinearLayout。 现在我需要在每个勾号按钮之间添加一条线,对齐方式如下所示 图像如下所示: 我应该使用什么布局来实现这一点 这是我当前的代码:(解决方案) 我已经根据@Piyush Gupta提供的解决方案修改了我的解决方案!谢谢大家的帮助Android-如何在linearlayouts之间生成线条,android,android-layout,android-xml,Android,Android Layout,Android Xml,我正在尝试使用XML生成一个如下所示的UI 蓝色勾号按钮和文本视图与垂直放置的LinearLayout对齐,因此在相对布局中总共有3个LinearLayout。 现在我需要在每个勾号按钮之间添加一条线,对齐方式如下所示 图像如下所示: 我应该使用什么布局来实现这一点 这是我当前的代码:(解决方案) 我已经根据@Piyush Gupta提供的解决方案修改了我的解决方案!谢谢大家的帮助 <RelativeLayout android:layout_width="mat
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp" >
<LinearLayout
android:id="@+id/linearlayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3" >
<ImageButton
android:id="@+id/button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_weight="1"
android:background="#000"
android:src="@android:color/transparent" />
<ImageButton
android:id="@+id/button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_weight="1"
android:background="#000"
android:src="@android:color/transparent" />
<ImageButton
android:id="@+id/button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearlayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linearlayout1"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="left"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
您可以使用视图显示此类线。在线性布局之间显示视图,并使用
android:layout\u toRightOf=“”
属性保持布局有序
<View android:layout_width="fill_parent"
android:background="@color/black"
android:layout_height="1dip" />
使用这个:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_toast_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F14E23"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_launcher" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_gravity="center"
android:background="#000"
android:src="@android:color/transparent" />
<ImageButton
android:id="@+id/button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_launcher" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_gravity="center"
android:background="#000"
android:src="@android:color/transparent" />
<ImageButton
android:id="@+id/button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
根据您的要求,在您需要的任何地方尝试xml文件中的以下代码。这将为您创建一条直线
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="2dp"
android:background="@color/black" >
</LinearLayout>
希望您可以管理线性布局“权重”选项。用以下代码替换xml。您可以根据需要调整重量
希望它能对您有所帮助。是的,我可以生成一条线,但我不知道如何将它放在按钮之间并垂直居中。线条还需要有动态宽度,因为它也应该缩放以适合平板电脑。感谢您的示例!然而现在看起来是这样的。。。仍然不是我希望实现的,我希望线条与按钮相接触,线条在按钮层内垂直居中,而不是包含TextView。嗨,Hari,我试过了,但它仍然看起来很奇怪,因为这条线粘在巴顿的左手边,与右边的巴顿分离…@cokeby你能显示一个屏幕截图吗?因为我在我的电脑里试过了,它看起来工作正常Hari,我的错误,我第二次试过了,现在看起来是这样的:但是,它并不是所有屏幕大小都是动态的,因为线条的像素宽度是固定的。@cokeby是的,我知道,我只是举了一个例子,说明了如何实现这一点感谢所有的帮助!谢谢你的帮助!这实际上也是可行的,但是在线条和按钮之间有一个间隙。但是对于另一个需要此实现的实现也会有所帮助!
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="2dp"
android:background="@color/black" >
</LinearLayout>
<LinearLayout
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:weightSum="10"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/button01"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@android:color/transparent"
android:src="@drawable/ic_add" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_weight="2"
android:background="@android:color/black" />
<ImageButton
android:id="@+id/button02"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@android:color/transparent"
android:src="@drawable/ic_add" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_weight="2"
android:background="@android:color/black" />
<ImageButton
android:id="@+id/button03"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@android:color/transparent"
android:src="@drawable/ic_add" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:weightSum="10"
android:orientation="horizontal" >
<TextView
android:id="@+id/TextView01"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="2"
android:text="TextView" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
<TextView
android:id="@+id/TextView02"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="2"
android:text="TextView" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
<TextView
android:id="@+id/TextView03"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="2"
android:text="TextView" />
</LinearLayout>