2012-04-28 63 views
0

这里我layout.xml文件如何将ImageView和TextView居中?

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

    <ImageView 
     android:id="@+id/image1" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:contentDescription="@string/desc" 
     android:padding="10dp" 
     android:layout_alignParentLeft="true"/> 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textColor="#FFF" 
     android:layout_toRightOf="@+id/image1"/> 

    <ScrollView 
     android:id="@+id/scroll" 
     android:layout_width="wrap_content" 
     android:layout_below="@+id/text1" 
     android:layout_height="40dp"/> 

    <ImageView 
     android:id="@+id/image2" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:contentDescription="@string/desc" 
     android:padding="10dp" 
     android:layout_below="@+id/image1"/> 

    <TextView 
     android:id="@+id/text2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textColor="#FFF" 
     android:layout_below="@+id/image1" 
     android:layout_toRightOf="@+id/image2"/> 


</RelativeLayout> 

我想用它上面的ImageView居中的TextView。我该怎么做呢?

我想它看起来像这样:取而代之的是ScrollView

<Player_Image> <Player_Name_Points> 
<Player_Image> <Player_Name_Points> 
+0

这两个图像和两个textview哪一个你想要中心 – 2012-04-28 02:49:30

+0

你也可以从日食(DDMS,在设备下有一个图标)截图, – 2012-04-28 03:06:50

回答

2

enter image description here

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <ImageButton 
     android:id="@+id/imageButton1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="24dp" 
     android:text="TextView" /> 

</RelativeLayout> 

尝试这样做......我想你会得到你想要的东西。

0

使用ListView用含有LinearLayout内的图像和文字(其他布局将工作)的自定义项。对于宽度使用wrap_content,对于重力使用center

绑定适配器,例如ArrayAdapterListView来控制显示的数据。