2012-04-28 47 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來控制顯示的數據。

相關問題