2016-07-06 108 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"/>