2016-07-06 106 views
0
Android Studio 2.1.1 

這就是我現在使用的下面的xml。 enter image description here在網格佈局中對齊列

但是,這是我的預期。 enter image description here

我想調整圖標旁邊的「最後售價$ 230」TextView。然而,「最後的銷售..」在第2列中,並且圖標在第1列中。

在GridLayout中可以這樣做嗎?

非常感謝您的任何建議,

我使用網格佈局,這是我的XML

android.support.v7.widget.GridLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:columnCount="3" 
    app:rowCount="5"> 

    <!-- Row 1 --> 
    <ImageView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_marginStart="8dp" 
     android:id="@+id/ivOptions" 
     android:src="@drawable/ic_remove_circle_outline_black_24dp"/> 

    <TextView 
     android:id="@+id/tvSize" 
     app:layout_columnSpan="2" 
     android:text="Size 8.0/ Tubular Doom Primeknit Core Black" 
     android:textSize="14sp" 
     android:textColor="@android:color/black" 
     android:fontFamily="sans-serif-condensed"/> 

    <!-- Row 2 --> 
    <TextView 
     android:id="@+id/tvPartNumber" 
     app:layout_column="1" 
     app:layout_columnSpan="2" 
     android:text="S74921" 
     android:textSize="12sp" 
     app:layout_row="1" /> 

    <!-- Row 3 --> 
    <ImageView 
     android:id="@+id/ivSneaker" 
     android:layout_width="80dp" 
     android:layout_height="50dp" 
     app:layout_gravity="center" 
     app:layout_columnWeight="1" 
     android:src="@drawable/sneakers_200" 
     android:scaleType="fitXY"/> 

    <include 
     android:id="@+id/top_offers" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     app:layout_gravity="center" 
     layout="@layout/top_offers"/> 

    <include 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     app:layout_gravity="center" 
     app:layout_columnWeight="1" 
     layout="@layout/offers_button"/> 

    <!-- Row 4 --> 
    <ImageView 
     android:layout_width="wrap_content" 
     app:layout_column="1" 
     android:layout_marginEnd="8dp" 
     android:src="@drawable/ic_trending_down_black_24dp"/> 

    <TextView 
     android:id="@+id/tvLastSale" 
     app:layout_gravity="center_vertical" 
     android:text="LAST SALE $230"/> 
</android.support.v7.widget.GridLayout> 

回答

0

管理通過創建圖標和文本的新的LinearLayout做到這一點。然後將其包括在第1欄中:

<!-- Row 4 --> 
<include 
    app:layout_column="1" 
    layout="@layout/last_sale_row"/>