4

I have three imageViews There I want to set all these ImageView into one line. I have pasted my current xml code below.

    <RelativeLayout
        android:id="@+id/myFragement"
        android:layout_width="wrap_content"
        android:layout_height="306dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="44dp"
        android:layout_weight="1.77"
        android:orientation="horizontal" >
    </RelativeLayout>

     <ImageView
         android:id="@+id/login_button"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:src="@drawable/login_non_click" />

    <ImageView
        android:id="@+id/comapre_now_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/compare_now_non_click_state" />

    <ImageView
        android:id="@+id/search_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/comapre_now_button"
        android:src="@drawable/search_non_click" />

</RelativeLayout>

After i have sloved. posted my App's image i think this is helpful all After editing i have posted my App's image i think this is helpful

After editing i have posted my App's all Xml code i think this is helpful all.

<RelativeLayout
    android:id="@+id/myFragement"
    android:layout_width="wrap_content"
    android:layout_height="306dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="44dp"
    android:layout_weight="1.77"
    android:orientation="horizontal" >

</RelativeLayout>

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal"
        android:weightSum="3" >
     <ImageView
             android:id="@+id/login_button"
                  android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"

             android:src="@drawable/login_non_click" />

        <ImageView
            android:id="@+id/comapre_now_button"
             android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
            android:src="@drawable/compare_now_non_click_state" />

        <ImageView
            android:id="@+id/search_button"
              android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
            android:src="@drawable/search_non_click" />

    </LinearLayout>

4

2 回答 2

11

像下面这样尝试,将ImageViews 放在一个LinearLayout带水平的内部orientation

     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:weightSum="3" >
         <ImageView
                android:id="@+id/login_button"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/login_non_click" />
         <ImageView
                android:id="@+id/comapre_now_button"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/compare_now_non_click_state" />
         <ImageView
                android:id="@+id/search_button"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/search_non_click" />   
        </LinearLayout>
于 2014-02-23T05:09:18.443 回答
6

fida 给出的答案应该提供您想要的(或接近它)。那是假设您希望它们全部占据屏幕的 1/3。否则,您可以消除该weight属性并在 s 之间使用 marginView或在它们之间使用空Views 并给出适当的weight.

您没有将它们放在水平布局中的原因是因为您android:layout_width="match_parent"首先拥有它们,ImageView所以我猜它占据了整个宽度。他们应该是android:layout_width="wrap_content"。此外,对于你的最后一个,你有android:layout_below="@+id/comapre_now_button"which 显然会将它放在Viewwith that之下id

假设你想要在中心,你可能想要android:layout_centerHorizontal="true"android:layout_toRightOf="@id/someId"android:layout_toLeftOf="id/someId"

此外,不是问题,但RelativeLayout没有orientationorweight属性。

于 2014-02-23T05:42:50.073 回答