简体   繁体   English

如何根据屏幕分辨率查看徽标?

[英]how to view logo depending upon screen resolution?

Hi I created one medical app. 嗨,我创建了一个医疗应用。 it,s working fine. 它,工作正常。 i placed one logo in center of the app screen my logo size height and width is 70x70 and my emulator screen resolution is 900 x 800 if i change my screen resolution i wish to change my logo size also dynamic. 我在应用程序屏幕的中心放置了一个徽标,我的徽标大小高度和宽度为70x70,如果我更改屏幕分辨率,我的仿真器屏幕分辨率为900 x 800我希望更改我的徽标大小也是动态的。 this is my doubt how to set logo depending upon the screen resolution? 这是我怀疑如何根据屏幕分辨率设置徽标?

code: 码:

public class ImageviewAppActivity extends Activity {

    private ImageView img; 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        img =(ImageView) findViewById(R.id.imagetest);
        img.setMaxWidth(20);
        img.setMaxHeight(100);


    }
}

xml: main.xml xml:main.xml

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

    <ImageView
        android:id="@+id/imagetest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

Look,I think you should set size of logog according to diffrent resolution then try to use 看,我认为你应该根据不同的分辨率设置logog的大小然后尝试使用

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
float density = metrics.density;

density is float and its value changed as per screen size... 密度是浮动的,其值根据屏幕大小而变化......

so,if you have 所以,如果你有

240*320 density is 0.5
320*480 density is 1.0
480*800 density is 1.5

and set size using density like , img.setMaxHeight(density*100); 并使用密度设置大小,如img.setMaxHeight(density*100);

and also put multiple screen supports in manifest file... Multiple Screen Support 并在清单文件中放置多个屏幕支持... 多屏支持

I'm not sure but you can play with the different screen resolution by the dpi. 我不确定你可以通过dpi玩不同的屏幕分辨率。 In your project you can create different drawable folder that allow you to put in your project different images with different resolution that will be loaded automatically from the device depending the screen resolution. 在您的项目中,您可以创建不同的可绘制文件夹,允许您将具有不同分辨率的不同图像放入项目中,这些图像将根据屏幕分辨率从设备自动加载。

http://developer.android.com/guide/practices/screens_support.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM