Prevent Android UI scaling

孤街醉人 提交于 2019-12-20 07:16:39

问题


Basically I have a series of imageviews within a linear layout. I've set each of the imageviews layout width and layout height properties to 100dp and 50dp respectively (I've also tried px instead of dp and I've tried changing the imageviews max size) but the imageviews continue to scale rather than staying at this fixed size.

I was just wondering if anyone knows what I am doing wrong?

XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="@drawable/backgroundtop" android:gravity="bottom">
    <FrameLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/frameLayout1">
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/imageView3" android:src="@drawable/base" android:layout_gravity="center"></ImageView>
        <LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" android:paddingTop="50px" android:layout_width="match_parent">
            <ImageView android:src="@drawable/buttonnews" android:id="@+id/imageView1" android:layout_width="123dp" android:layout_height="49dp" android:scaleType="center"></ImageView>
            <ImageView android:id="@+id/imageView2" android:layout_width="163dp" android:layout_height="49dp" android:src="@drawable/buttonevents"></ImageView>
        </LinearLayout>
    </FrameLayout> 
</LinearLayout> 

回答1:


Have you tried to set scaleType of ImageView to fitCenter?




回答2:


Unit of measurement supported by android can be :

px
Pixels - corresponds to actual pixels on the screen.

in
Inches - based on the physical size of the screen.

mm
Millimeters - based on the physical size of the screen.

pt
Points - 1/72 of an inch based on the physical size of the screen.

dp
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ration of dp-to-pixel will change with the screen density, but not necessarily directly; instead the ratio is selected is something that is close to the screen.

sp
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.



来源:https://stackoverflow.com/questions/5605652/prevent-android-ui-scaling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!