Reputation: 387
I'm using a ListView, for each item I created an imageview + an edittext. I load images from a website and I don't understand why some images have not a width of 35%. However I use the layout_weight property. Can you tell me how to force the image to take 35% of the width ?
For example, the result i have now :
And here is my code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="3"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.3"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="@+id/poster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:layout_weight="0.35"
android:contentDescription="42"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.65"
android:text="Title"
/>
</LinearLayout>
</LinearLayout>
If you see what is wrong :/
Best regards, Zed13
Edit : The result with Rishi Paul solution
And the updated xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="3"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="@+id/poster"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:layout_weight="0.35"
android:scaleType="fitCenter"
android:contentDescription="42"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.65"
android:text="Title"
/>
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 975
Reputation: 936
Do Like This. It Will Help You
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/poster"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:layout_weight="0.35"
android:adjustViewBounds="true"
android:contentDescription="42"
android:src="@drawable/desert" />
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.65"
android:text="Title" />
</LinearLayout>
Upvotes: 2