2013-02-23 63 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

相关问题