【问题标题】:Android Layout, scale width to screen resolutionAndroid 布局,将宽度缩放到屏幕分辨率
【发布时间】:2012-07-10 02:30:52
【问题描述】:

我想调整图像的大小以适应屏幕以填充整个宽度。高度应设置为纵横比。 例如图像尺寸是宽x高10x5,手机是400宽。图片应以 200x400 显示。

我尝试了一些设置 android:scaleType="center" 根据文档应该是正确的设置,但似乎没有效果, android:scaleType="centerCrop" 适合高度并使宽度大于屏幕。

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageViewFrage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:padding="1dp"
        android:scaleType="centerCrop"
        android:src="@drawable/bg_striped_img" />
</LinearLayout>

</LinearLayout>

非常感谢

【问题讨论】:

    标签: android layout


    【解决方案1】:

    你应该试试android:scaleType="centerInside"

    根据文档 (http://developer.android.com/reference/android/widget/ImageView.ScaleType.html):

    均匀缩放图像(保持图像的纵横比),使图像的两个尺寸(宽度和高度)都等于或小于视图的相应尺寸(减去填充)。然后图像在视图中居中。

    【讨论】:

    • 没用,将图像居中,但使用图像的宽度和高度。也试过 android:layout_width="match_parent" android:layout_height="match_parent"
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2012-08-31
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多