LinearLayout with two children of equal width

后端 未结 5 557
北荒
北荒 2021-01-17 11:26

I\'m having some issues getting two children of a LinearLayout to have the same width. This is what I am getting:

相关标签:
5条回答
  • 2021-01-17 11:49

    Equally weighted children

    To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1". Refer : http://developer.android.com/guide/topics/ui/layout/linear.html

    0 讨论(0)
  • 2021-01-17 11:49

    Remove the weight sum from your Parent View (@+id/profile_action_rate_user).

    0 讨论(0)
  • 2021-01-17 11:53

    this is you want:

    try this xml @boz:it will run in all size of layouts...!

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".50"
            android:background="@drawable/ic_launcher" >
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".50"
            android:orientation="vertical" >
    
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="33.33" >
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="33.33"
                android:background="@android:color/darker_gray" >
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="33.33" >
            </LinearLayout>
        </LinearLayout>
    
    </LinearLayout>
    

    i take two linear layout with(50%,50%),and three child linear layout with(33.33%,33.33%,33.33%).among there three layouts, 2nd layout is your pinkone.

    if still any query,plz ask.

    0 讨论(0)
  • 2021-01-17 11:58

    android:weightSum="2" should be on the parent of the two children ImageViews, not on the upper parent. Or else try to set weightsas 0.5 and see if it works.

    Also, the widths of the two image views should be android:layout_width="0dp" when using weights like this.

    Next, scale up your images to fill space. Details here.

    0 讨论(0)
  • 2021-01-17 12:13

    You can use something like this,hope this will fit your requirement. Try this xml .

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/Black"
            android:gravity="center"
            android:orientation="vertical" 
            android:layout_weight="0.5"
            >
    
            <TextView
                android:id="@+id/profile_rate_header"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Rate User"
                />
    
            <LinearLayout 
                android:id="@+id/profile_action_rate_user"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center"
                >
    
                <ImageView 
                    android:id="@+id/profile_action_rate_up"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/close"
                    />
    
                <ImageView 
                    android:id="@+id/profile_action_rate_down"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/close"
                    />
    
            </LinearLayout>
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:orientation="vertical" >
    
            <ImageView
                android:id="@+id/profile_photo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                android:src="@drawable/close" />
    
        </LinearLayout>
    
    </LinearLayout>
    
    
    </LinearLayout>
    
    0 讨论(0)
提交回复
热议问题