[英]Android layout creating two rows with one column combined for the picture
我正在尝试创建这样的布局。 首先, GridLayout
是实现此目标的最佳方法吗? 我尝试了许多不同的布局,但是每种布局都有自己的问题。 下面是我尝试的代码。 任何帮助表示赞赏。 提前致谢。
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:columnCount="3">
<ImageButton
android:src="@drawable/avatar_male_update"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_height="100dp"
android:layout_width="100dp"
android:layout_row="0"
android:layout_column="0"
android:id="@+id/imageButtonMale" />
<Button
android:text="Refresh"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="@drawable/mybutton"
android:layout_row="0"
android:layout_column="1"
android:id="@+id/btnCSRefresh" />
<Button
android:text="Change Avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/mybutton"
android:layout_row="0"
android:layout_column="2"
android:id="@+id/btnChangeAvatar" />
<LinearLayout
android:orientation="vertical"
android:layout_row="1"
android:layout_column="0"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/linearLayoutButtons">
<TextView
android:text="Welcome "
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtViewHeader"
android:background="#FE6A00" />
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lstViewSummary" />
</LinearLayout>
对我来说,您真正想要的不是很清楚,因为您在xml中使用列表视图,因此请更清楚地发布问题。
尝试此为您的布局:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="100dp" android:minWidth="100dp" android:src="@drawable/ic_launcher" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button1" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button1" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button2" android:layout_toRightOf="@+id/button3" /> </RelativeLayout> </LinearLayout>
我应该拒绝您的问题,因为您的xml与您的图片不符!
但是,如果您想要在图片中绘制的内容:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:align_parentLeft="true"
android:center_in_vertical="true"
android:id="@+id/imageButtonMale"
android:layout_height="100dp"
android:layout_width="100dp" />
<View
android:id="@+id/spacer1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:align_toRightOf="@id/imageButtonMale"
android:center_vertical="true" />
<Button
android:text="Refresh"
android:id="@+id/btnCSRefresh"
android:layout_above="@id/spacer1"
android:align_toRightOf="@id/imageButtonMale"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:text="Change Avatar"
android:id="@+id/btnChangeAvatar"
android:layout_above="@id/spacer1"
android:align_toRightOf="@id/btnCSRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="Row2Col1"
android:id="@+id/button_below_refresh_button"
android:layout_below="@id/spacer1"
android:align_toRightOf="@id/imageButtonMale"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:text="Row2Col2"
android:id="@+id/button_below_change_avatar_button"
android:layout_below="@id/spacer1"
android:align_toRightOf="@id/button_below_in_col1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
一些要点:
这将环绕起来,这意味着如果您希望将其扩展到屏幕宽度,则可以将相对布局父级宽度更改为match_parent
。 现在,如果您希望按钮的宽度相等,则可以将其宽度更改为match_parent
但是必须将android:align_parentRight
更改为第2列中的两个按钮,并将android:align_toLeftOf="@id/button_in_col2"
到第一列中的按钮(即第一列中的按钮位于imageview的右侧,第二列中的按钮的右侧;第二列中的按钮与其父级对齐;两个按钮均将父级与上述匹配)对齐将占用相等的空间)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.