【发布时间】:2019-01-07 06:34:20
【问题描述】:
我正在尝试并排制作一个按钮和一个彩色矩形。我不确定是否需要使用线性布局、网格布局或其他方式来执行此操作。这是我尝试过的:
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_row="0"
app:layout_column="0"
android:text="Button" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_row="1"
app:layout_column="0"
android:text="Button" />
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@android:color/holo_blue_bright"
app:layout_column="1"
app:layout_gravity="fill"
app:layout_row="0" />
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@android:color/holo_green_dark"
app:layout_column="1"
app:layout_gravity="fill"
app:layout_row="1" />
</android.support.v7.widget.GridLayout>
顶部看起来正确。我想要一个薄按钮,旁边有一个同样薄的矩形。我无法使底部工作。执行此操作的最有效方法是什么,最好以编程方式添加新行(从 2 行开始并添加更多行)。
【问题讨论】:
-
试试这个,将 girdlayout 高度 match_parent 更改为 wrap_content
标签: android gridview view alignment