【问题标题】:Scale imageview on tablet with original aspect在具有原始方面的平板电脑上缩放图像视图
【发布时间】:2015-10-20 23:24:30
【问题描述】:

我有下面的代码,我在图像视图“@+id/logo_skillfull”中遇到了问题,因为它不保留方面。我认为是因为 scaleType 或 adjustViewBounds..

image in tablet

image in a phone (I want this)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayoutMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:keepScreenOn="true" >

    <View
        android:id="@+id/view"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/view2"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/view"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/registration_background"
        android:orientation="vertical"
        android:padding="25dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/member_login_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="15dp"
                android:text="Ingresá tu DNI"
                android:textSize="25dp"
                android:textStyle="bold"
                android:typeface="monospace" />

            <EditText
                android:id="@+id/username_edtext"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/member_login_tv"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/register_uname"
                android:gravity="center"
                android:hint="Documento"
                android:imeOptions="actionDone"
                android:inputType="number"
                android:singleLine="true"
                android:textColor="#000000"
                android:textSize="30dp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/login_button"
                style="@style/button_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/username_edtext"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/button_access"
                android:text="Aceptar"
                android:textColor="#ffffff" />

            <ImageView
                android:id="@+id/logo_skilfull"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:layout_gravity="center"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/logos"
                android:scaleType="matrix"
                android:layout_alignParentBottom="true"  />
        </RelativeLayout>
    </LinearLayout>

    <View
        android:id="@+id/view2"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true" />

    <ImageView
        android:id="@+id/view_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:background="@drawable/member_imview" />

</RelativeLayout>

【问题讨论】:

    标签: java android imageview scale


    【解决方案1】:

    你应该阅读ImageView

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
    

    这是更改视图大小的问题。你需要设置 scaleType。

    试试 fitStart。

    <ImageView
                    android:id="@+id/logo_skilfull"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:layout_gravity="center"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/logos"
                    android:scaleType="fitStart"
                    android:layout_alignParentBottom="true"  />
    

    【讨论】:

    • 什么不起作用?您可以使用其他 scaleType:CENTER_CROP 等
    • 啊!它可以与其中之一一起使用吗?我必须把 adjustViewBounds="true" AND any scaleType?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多