【发布时间】:2014-07-22 16:39:23
【问题描述】:
我有 ImageView 需要以可用的全高显示。但是在顶部,我创建了包含文本和图像的 LinearLayout。我希望它显示在顶部,但也希望图像适合屏幕。我在底部有线性布局,并且工作正常。
这是我想在顶部显示的 LinearLayout 代码。我隐藏了操作栏
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@android:color/black"
android:gravity="top"
android:orientation="horizontal"
android:visibility="visible" >
<ImageView
android:id="@+id/backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingLeft="10dp"
android:src="@drawable/back_button" />
<TextView
android:id="@+id/titleofscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Testing"
android:textColor="#22c064"
android:textSize="18sp" />
</LinearLayout>
<ImageView
android:id="@+id/imageShown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</FrameLayout>
如果我没有将 imageView 比例类型设置为 android:scaleType="fitXY" 那么它可以工作,但图像不适合屏幕。
我想显示图像以适合包含文本的上方栏和下方有一些图标的栏。但是,如果我制作图像 scaletype ='fitXY' 它不会显示在文本上方。以下是屏幕截图,但我希望图像占用空间
【问题讨论】:
-
请发布有关您获得的结果的更多详细信息。 “它不起作用”有点不足以理解你的问题。此外,我不确定您要实现什么 - 是否只是显示填充整个屏幕的图像?顺便提一句。为什么要使用
android:scaleType="fitXY"?大多数人关心纵横比,fitXY不会保持纵横比。也许您应该使用centerCrop或centerInside(取决于您想要实现的目标)。