Build menu with LinearLayout and ImageView
I try to build menu with LinearLayout and ImageView on the bottom of the screen
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#343434"
android:gravity="left"
android:paddingTop="5px"
android:weightSum="1.0">
<ImageView xmlns:android="http://schemas.android.com/apk/res/an开发者_运维知识库droid"
android:gravity="left"
android:id="@+id/home_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/home_1"
android:layout_weight=".20"/>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="left"
android:id="@+id/tournament_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tournament_2"
android:layout_weight=".20"/>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="left"
android:id="@+id/massages_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/massages_2"
android:layout_weight=".20"/>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="left"
android:id="@+id/players_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/players_2"
android:layout_weight=".20"/>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="left"
android:id="@+id/settings_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/settings_2"
android:layout_weight=".20"/>
</LinearLayout>
I actually trying to make menu for various size screens but when images are adapted to the width of the screen and when the images are reduced main LinearLayout remains the same in height it's like it has size of images with initial height. So where are my mistakes here? And can I do this in other way?
Thanks.
Try adding
android:adjustViewBounds="true"
to each of your ImageViews.
ie:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="left"
android:id="@+id/home_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/home_1"
android:adjustViewBounds="true"
android:layout_weight=".20"/>
精彩评论