Reputation: 1432
I have a horizontal LinearLayout with 3 ImageViews, but ImageView are much more wider than image are(rectangle when image is square). I've try to set adjustViewBound="true", than imageView become square but much more bigger. Also I've tryed to set scaleType="firXY" but then the image is scaling to fit rectangle imageView. Here is ma xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/llButtons">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_start_text"
android:id="@+id/imgStart"
android:layout_weight="1.5"
android:src="@drawable/ic_play"/>
<ImageView
android:id="@+id/imgReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:text="@string/button_reset_text"
android:src="@drawable/ic_cls"/>
<ImageView
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:text="@string/button_next_text"
android:src="@drawable/ic_next"/>
</LinearLayout>
And this is a result:
How can I set ImageView size as picture size?
Upvotes: 2
Views: 2907
Reputation: 26
dp
) or use fill_parent
android:scaleType
to fitXY
.Upvotes: 0
Reputation: 1432
Thank you all, I've solved it. Following advice of @Khizar Hayat I've delete wight attribute and use wrap content instead. To place my ImageViews by screen sides and center I've using .
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/llButtons">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_start_text"
android:id="@+id/imgStart"
android:src="@drawable/ic_play"/>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_reset_text"
android:src="@drawable/ic_cls"/>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<ImageView
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_next_text"
android:src="@drawable/ic_next"/>
</LinearLayout>
Upvotes: 0
Reputation: 6357
I assume you want to keep the images equidistant horizontally. Create a LinearLayout
for each image, give each a weight of 1
(remove weights from ImageView
s), and set each LinearLayout
's gravity
to center
.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/llButtons"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_start_text"
android:id="@+id/imgStart"
android:src="@drawable/ic_play"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:id="@+id/imgReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_reset_text"
android:src="@drawable/ic_cls"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_next_text"
android:src="@drawable/ic_next"/>
</LinearLayout>
</LinearLayout>
Upvotes: 1
Reputation: 361
You had assigned the weight as 1.5 and this makes the issue. Anyway You can adjust the width of each images By previewing the layout.
This gives you the proper idea how to manage items in a Linear Layout.
Upvotes: 1