Android 设计一个视图,使图标填满屏幕,但不拉伸图像
我目前有以下布局(见下文)。现在我遇到的问题是,我需要图标来填充屏幕(因此我需要将屏幕分为6个块。但最大的问题是我的图像正在拉伸,这看起来非常糟糕。所有图像都是256X256。我该怎么做才能在上面或下面有更多的空间,而不是拉伸它们 布局Android 设计一个视图,使图标填满屏幕,但不拉伸图像,android,android-layout,android-image,Android,Android Layout,Android Image,我目前有以下布局(见下文)。现在我遇到的问题是,我需要图标来填充屏幕(因此我需要将屏幕分为6个块。但最大的问题是我的图像正在拉伸,这看起来非常糟糕。所有图像都是256X256。我该怎么做才能在上面或下面有更多的空间,而不是拉伸它们 布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linLayout" android:layout_width="matc
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.60"
android:orientation="horizontal"
android:weightSum="3" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="@+id/category_menu_button_food"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/menu_icon"
android:contentDescription="Food Menu"
android:onClick="foodMenuItemClicked"
android:scaleType="centerInside" />
<TextView
android:id="@+id/category_menu_label_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:ems="20"
android:gravity="center"
android:text="Menu"
android:textSize="25sp" >
<requestFocus />
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/search_icon"
android:contentDescription="Drinks Menu"
android:onClick="searchMenuItemClicked"
android:paddingTop="55dp"
android:scaleType="centerInside" />
<TextView
android:id="@+id/category_menu_label_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:ems="20"
android:gravity="center"
android:text="Search"
android:textSize="25sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/cart_icon"
android:contentDescription="Favorites"
android:onClick="favoritesMenuItemClicked"
android:scaleType="centerInside" />
<TextView
android:id="@+id/category_menu_label_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:ems="20"
android:gravity="center"
android:text="Cart"
android:textSize="25sp" >
</TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.60"
android:orientation="horizontal"
android:weightSum="3" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/bill_icon"
android:contentDescription="View Bill"
android:onClick="billMenuItemClicked"
android:scaleType="centerInside" />
<TextView
android:id="@+id/category_menu_label_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:ems="20"
android:gravity="center"
android:text="Bill"
android:textSize="25sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="@+id/activity_category_menu_button_callWaiter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/callwaiter_icon"
android:contentDescription="Call Waiter"
android:onClick="callWaiterButtonClicked"
android:scaleType="centerInside" />
<TextView
android:id="@+id/category_menu_label_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:ems="20"
android:gravity="center"
android:text="Call Waiter"
android:textSize="25sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/exit_icon"
android:contentDescription="Exit App"
android:onClick="exitButtonClicked"
android:scaleType="centerInside" />
<TextView
android:id="@+id/category_menu_label_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:ems="20"
android:gravity="center"
android:text="Exit App"
android:textSize="25sp" >
</TextView>
</LinearLayout>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content" />
我认为您可以使用
包装内容来查看ImageView
和
您可以使用RelativeLayout而不是LinearLayout
您在布局的根目录中使用RelativeLayout,在根目录的子目录中使用两个ReltavieLayout。为了不拉伸图像,您应该为不同大小和密度的设备使用不同大小的图像。不要设置图像的宽度和高度,将高度/宽度属性保留为包裹内容这样,图像既不会收缩也不会拉伸。请尝试更改宽度和高度以包装内容,而不是提供匹配的父对象。
或者将scaletype更改为fitxy。更改scaletype。您可能需要fitCenter。好的,我已经尝试了所选的。现在图标很小,并且有足够的空间。有没有办法现在可以放大它们。但是不影响纵横比?是的,您可以阅读scaletype
的文档,其中解释了每种可能的情况价值观或做我所做的,尝试不同的价值观,看看他们有什么影响。