【发布时间】:2014-08-03 13:29:36
【问题描述】:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="6"
android:gravity="center"
android:paddingLeft="5dp">
<RelativeLayout
android:id="@+id/child_one"
android:layout_height="match_parent"
android:layout_width="0dp"
android:gravity="center"
android:layout_weight="0.7">
<Button android:id="@+id/buttonhome1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:background="@drawable/"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_below="@+id/buttonhome1"
android:text="@string/Main"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/child_two"
android:layout_height="match_parent"
android:layout_width="0dp"
android:gravity="center"
android:visibility="invisible"
android:layout_weight="1.8">
<Button android:id="@+id/childBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="0dp"
android:background="@drawable/"/>
<TextView
android:id="@+id/childtxt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:layout_centerVertical="@+id/childBtn1"
android:layout_toRightOf="@+id/childBtn1"
android:text="@string/text1"/>
<Button android:id="@+id/childBtn2"
android:layout_width="wrap_content"
android:layout_height= "wrap_content"
android:focusable="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="80dp"
android:layout_below="@+id/childBtn1"
android:background="@drawable/"/>
<TextView
android:id="@+id/childtxt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:layout_below="@+id/childBtn1"
android:layout_toRightOf="@+id/childBtn2"
android:text="@string/text2"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/child_three"
android:layout_height="match_parent"
android:visibility="visible"
android:layout_width="0dp"
android:layout_weight="1.8" />
<RelativeLayout
android:id="@+id/child_four"
android:layout_height="match_parent"
android:layout_width="0dp"
android:visibility="visible"
android:layout_weight="1.7"/>
</LinearLayout>
在动态按钮之间画线
我的线性布局中有三个相对布局。
Layout 1 有主按钮,当在主按钮上执行点击操作时,通过代码生成相对layout 2 中的动态按钮。
我的问题是,我可以使用图形类通过动态方式跨布局绘制线条来连接主按钮及其子按钮layout 2 吗?
【问题讨论】:
-
您可以在添加按钮时在相对布局中添加具有黑色(根据需要)背景和 layout_width = "match_parent", layout_height="1dp" 的视图。
-
我用
TextView用background颜色和height = 2dp画线:D -
如果我这样做,行将仅在特定布局中作为元素。它如何从布局 1 连接到布局 2。布局使用 layout_weight 分隔。例如:我需要类似节点树的东西我的布局
-
发布我们的 xml 以便更好地理解问题。
标签: android android-layout android-canvas