2013-12-09 68 views
0

我是Android新手,我想將TextView放在TableRow中ImageView的中心。 textView與圖像視圖分開,我如何將textView放置在imageView頂部?並且因爲它在tableRow中,所以我不能使用layout_alignLeft或layout_alignRight來居中。將TextView放置在TableRow中ImageView的中心

非常感謝您的幫助。

喜歡的東西:

<TableRow> 
<ImageView 
    android:id="@+id/durationView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/blk_duration" 
    android:contentDescription="@string/logo" 
    android:layout_weight="1" /> 

    <TextView 
     android:id="@+id/durationTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="@string/duration" 
     android:textColor="@color/text_color" 
     android:textSize="@dimen/font_size_duration" /> 

    <ImageView 
    android:id="@+id/durationView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/blk_duration" 
    android:contentDescription="@string/logo" 
    android:layout_weight="1" /> 

    <TextView 
     android:id="@+id/durationTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="@string/duration" 
     android:textColor="@color/text_color" 
     android:textSize="@dimen/font_size_duration" /> 

</TableRow> 

回答

0

嘗試以下佈局:

<TableRow> 
    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" > 

     <ImageView 
      android:id="@+id/durationView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/logo" 
      android:src="@drawable/blk_duration" /> 

     <TextView 
      android:id="@+id/durationTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:gravity="center" 
      android:text="@string/duration" 
      android:textColor="@color/text_color" 
      android:textSize="@dimen/font_size_duration" /> 

    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="odp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" > 

     <ImageView 
      android:id="@+id/durationView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/logo" 
      android:src="@drawable/blk_duration" /> 

     <TextView 
      android:id="@+id/durationTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:gravity="center" 
      android:text="@string/duration" 
      android:textColor="@color/text_color" 
      android:textSize="@dimen/font_size_duration" /> 

    </RelativeLayout> 
</TableRow> 
+0

非常感謝:) – jenjenjen

0

使用內部tablerow的一個RelativeLayout的。然後在relativelayout裏放置imageview和textview。相應地調整你的textview,把它拖到你需要放置的地方。希望我回答你的問題。

+0

我試圖放置的TableRow內部的相對佈局,但寬度比畫面更寬。 – jenjenjen

+0

使用相對佈局匹配的佈局寬度 –

相關問題