试图将2张图像并排放置并居中(它们总是左对齐)

时间:2013-10-06 00:47:58

标签: android android-layout

我正在为我的应用程序整理布局。在底部,我希望将2 ImageView并排放置在中心位置,但它们是左对齐的。我将引力设置为中心,而不是工作。

Xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff29245c"
    android:orientation="vertical" >

    <ScrollView 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent">  

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <ImageView                  
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/parschute"
                android:id="@+id/ok"    
                android:layout_gravity="center"
                android:layout_marginTop="12px" />  

            <LinearLayout 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal" >

            // WOULD LIKE THE 2 IMAGEVIEWS BELOW TO BE NEXT TO BE ON SAME LINE AND CENTERED

                <ImageView                  
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/pulldown"
                    android:layout_gravity="center"/>        

                    <ImageView                  
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/camera"  
                    android:layout_gravity="center"/>        

            </LinearLayout>                 
        </LinearLayout>        
    </ScrollView>         
 </LinearLayout>

1 个答案:

答案 0 :(得分:0)

我想这就是你正在尝试的.-

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

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#0000FF" />

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#00FFFF" />
    </LinearLayout>

</RelativeLayout>

产生这个结果.-

Layout screenshot

(注意我拍了布局下半部分的截图)