0

I have a LinearLayout and in LinearLayout I have a ImageView and a TextView. I want to set %50 width each of them. I used weightSum and layout_weight for this purpose but my it is not working. How can I set 50% width to each Views

As you can see below weight = 10 and TextView and ImageView has 5 for weight

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:background="#3e4231"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hakkikonu.countriesultimate.CountryDetails" >

<TextView
    android:id="@+id/tv_show_extra"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="0dp"
    android:layout_marginTop="0dp"
    android:background="#ff4444"
    android:text="Country Name"
    android:textColor="#FFFFFF"
    android:textSize="24sp" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="10" >

    <ImageView
        android:id="@+id/iv_bayrak_goster"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:adjustViewBounds="true"
        android:baselineAlignBottom="false"
        android:src="@drawable/default_flag" />

    <TextView
        android:id="@+id/tv_capital"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        android:layout_marginTop="0dp"
        android:background="#ff4444"
        android:text="Capital"
        android:textColor="#FFFFFF"
        android:textSize="16sp" 
        android:layout_weight="5"/>

</LinearLayout>

hakki
  • 6,181
  • 6
  • 62
  • 106
  • take a look at this post :http://stackoverflow.com/questions/3025048/set-imageviews-max-width-as-a-percent-of-its-parents-width – Elior Apr 06 '13 at 20:07

1 Answers1

0

For the layout with the weightsum of 10, set android:layout_width to 0dp rather than match parent.

Graham Smith
  • 25,627
  • 10
  • 46
  • 69
  • http://stackoverflow.com/questions/15696920/android-layout-layoutweight-and-weightsum see this stack overflow answer that relates. – Graham Smith Apr 06 '13 at 20:17