Android 布局:我的图像只占屏幕的大约 2/3
Android Layout: My images are filling only about 2/3 of my screen
我有一个新的 Activity 以及相关的布局,效果很好。
除了 ImageView(s) 没有覆盖我屏幕的整个宽度。
我正在使用 Android Studio(最新的稳定版),令人惊讶的是,在 IDE 中,我的布局预览看起来不错。但是当我 运行 我的设备(或模拟器)上的应用程序时,它并没有覆盖整个屏幕。
这是我的布局设计:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="@+id/scrollView1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/cat_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_food" />
<ImageView
android:id="@+id/cat_drink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_drink" />
<ImageView
android:id="@+id/cat_coffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_coffee" />
<ImageView
android:id="@+id/cat_shopping"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_shopping" />
<ImageView
android:id="@+id/cat_offers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_offers" />
</LinearLayout>
</ScrollView>
<include
android:id="@+id/action_bar"
layout="@layout/layout_actionbar" />
知道我做错了什么吗?
感谢您的帮助。
P.S。
我已经尝试了 wrap_contents、match_parent、fill_parent,其中 none 解决了问题。
将 ImageView 宽度设置为 fill_parent
或 match_parent
并另外使用 android:scaleType="fitXY"
我对此进行了测试,ImageView 填满了整个屏幕宽度。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/cat_food"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
<ImageView
android:id="@+id/cat_drink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
<ImageView
android:id="@+id/cat_coffee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
<ImageView
android:id="@+id/cat_shopping"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
<ImageView
android:id="@+id/cat_offers"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
</LinearLayout>
</ScrollView>
<include
android:id="@+id/action_bar"
layout="@layout/layout_actionbar" />
</LinearLayout>
我有一个新的 Activity 以及相关的布局,效果很好。 除了 ImageView(s) 没有覆盖我屏幕的整个宽度。
我正在使用 Android Studio(最新的稳定版),令人惊讶的是,在 IDE 中,我的布局预览看起来不错。但是当我 运行 我的设备(或模拟器)上的应用程序时,它并没有覆盖整个屏幕。
这是我的布局设计:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="@+id/scrollView1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/cat_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_food" />
<ImageView
android:id="@+id/cat_drink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_drink" />
<ImageView
android:id="@+id/cat_coffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_coffee" />
<ImageView
android:id="@+id/cat_shopping"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_shopping" />
<ImageView
android:id="@+id/cat_offers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/cat_offers" />
</LinearLayout>
</ScrollView>
<include
android:id="@+id/action_bar"
layout="@layout/layout_actionbar" />
知道我做错了什么吗?
感谢您的帮助。
P.S。 我已经尝试了 wrap_contents、match_parent、fill_parent,其中 none 解决了问题。
将 ImageView 宽度设置为 fill_parent
或 match_parent
并另外使用 android:scaleType="fitXY"
我对此进行了测试,ImageView 填满了整个屏幕宽度。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/cat_food"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
<ImageView
android:id="@+id/cat_drink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
<ImageView
android:id="@+id/cat_coffee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
<ImageView
android:id="@+id/cat_shopping"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
<ImageView
android:id="@+id/cat_offers"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="@drawable/ic_logo" />
</LinearLayout>
</ScrollView>
<include
android:id="@+id/action_bar"
layout="@layout/layout_actionbar" />
</LinearLayout>