Android ImageView超出父边界?
我对Android开发还不熟悉,但我似乎遇到了一个非常简单的问题。我尝试用三种线性布局布局屏幕,顶部占12.5%,中间占73%,底部占14.5%。在顶部区域中,我想放置一个相对布局,在顶部线性布局中包含一个ImageView。(这个布局还有很多内容,包括按钮和所有东西,但我把它删去以显示问题) 如果我移除ImageView,所有的东西都会被完美地遮挡,我会得到正确大小的矩形区域。但在ImageView中,顶部线性区域的高度至少扩展到屏幕的3/4 我希望相对线保持在顶部线性区域内。有什么想法吗 顺便说一下,我的可拉拔/顶部_条本机宽800px,高186px 布局如下:Android ImageView超出父边界?,android,android-layout,Android,Android Layout,我对Android开发还不熟悉,但我似乎遇到了一个非常简单的问题。我尝试用三种线性布局布局屏幕,顶部占12.5%,中间占73%,底部占14.5%。在顶部区域中,我想放置一个相对布局,在顶部线性布局中包含一个ImageView。(这个布局还有很多内容,包括按钮和所有东西,但我把它删去以显示问题) 如果我移除ImageView,所有的东西都会被完美地遮挡,我会得到正确大小的矩形区域。但在ImageView中,顶部线性区域的高度至少扩展到屏幕的3/4 我希望相对线保持在顶部线性区域内。有什么想法吗 顺
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/masterLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="false"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/linearTop"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".125"
android:orientation="horizontal"
android:layout_alignParentTop="true" >
<RelativeLayout
android:id="@+id/topToolbarRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" >
<ImageView
android:id="@+id/topBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitStart"
android:src="@drawable/top_bar" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/linearMiddle"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight=".730">
</LinearLayout>
<LinearLayout
android:id="@+id/linearBottom"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_weight=".145">
</LinearLayout>
</LinearLayout>
您可以尝试将比例因子设置为fitXY。比如:
android:scaleType="fitXY"
您可以尝试将比例因子设置为fitXY。比如:
android:scaleType="fitXY"
我刚刚测试过。将ImageView更改为以下内容:
<ImageView
android:id="@+id/topBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="fitStart"
android:src="@drawable/top_bar" />
我刚刚测试过它。将ImageView更改为以下内容:
<ImageView
android:id="@+id/topBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="fitStart"
android:src="@drawable/top_bar" />
这肯定行得通,我只是不明白为什么“fill\u parent”并不真正意味着fill parent!这就是为什么从API第8级开始使用“fill_parent”的原因。这确实有效,我只是不明白为什么“fill_parent”并不真正意味着fill parent!这就是为什么从API级别8开始“填充父对象”。