簡體   English   中英

Android布局創建兩行,其中一列合並為圖片

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM