2013-02-23 64 views
2

我使用這種佈局來製作圖像和文本在center.but它不工作。我簡單地使用android:layout_centerHorizo​​ntal =「true」.why它不工作我不明白。有人可以幫助解決這個問題嗎?android:layout_centerHorizo​​ntal =「true」在android中不工作

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#ffffff"> 


     <ImageView 
      android:id="@+id/image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="70dp" 
      android:background="@drawable/image_tutorial1" /> 

     <TextView 
      android:textSize="14dp" 
      android:id="@+id/title" 
      android:layout_below="@+id/image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="@string/info4" 
      android:textColor="#000000" 
      android:textStyle="bold" /> 

    </RelativeLayout> 

回答

0

使用[機器人:layout_centerHorizo​​ntal = 「真」]下的RelativeLayout佈局,然後,將工作

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 
+0

即時通訊使用相對佈局,但它不working.i也嘗試linearlayout,但也不起作用 – 2013-02-23 13:17:33

+0

它只在相對佈局下工作,然後它的工作,我使用了很多次 – Rohit 2013-02-23 13:18:04

+0

你試過主佈局將linearlayout和textview將在相對佈局 – Rohit 2013-02-23 13:19:29

2

在佈局,RelativeLayout的寬度被設定爲wrap-content,它不是將整個可用寬度。它的內容居中,但他們的父母View正在縮小以適應他們。

嘗試fill_parent根:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 

此外,LinearLayoutorientation="vertical"gravity="center_horizontal"會做同樣的,也更容易。

+0

我也試過這個,但沒有奏效。 – 2013-02-23 14:01:12

相關問題