我该如何调整布局和滚动型根据屏幕分辨率 [英] How can i resize the layout and scrollview according to screen resolution

查看:138
本文介绍了我该如何调整布局和滚动型根据屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置布局和滚动视图屏幕分辨率为480x800。我怎么能与其他的屏幕分辨率兼容吗?
这里是我的code。请帮我。

I set the layout and scroll view for the screen resolution 480x800. How can I be compatible with other screen resolution? Here is my code. Please help me.

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="150dp"
android:orientation="vertical" >
<ScrollView android:id="@+id/ScrollView01"
 android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#86C3C6" >
<TextView
        android:id="@+id/tvHistory"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#86C3C6"
        android:gravity="right"
        android:focusable="true"
        android:text=""
        android:textColor="#FFFFFF" />
 </ScrollView>
</RelativeLayout>

请帮我设置布局,滚动视图,并通过TEXTSIZE程序

Please help me to set the layout,scroll view and textsize through program

推荐答案

首先,Android不支持的概念屏幕分辨率。有屏幕大小和屏幕(或像素)密度。既然你已经使用密度独立像素(DP),我想,你的问题是关于支持不同的屏幕尺寸。

First of all, Android does not support the concept of "screen resolution." There's screen size and screen (or pixel) density. Since you're already using density-independent pixels (dp), I imagine that your question is about supporting different screen sizes.

要支持其它屏幕尺寸的方法是具有特定大小的资源目录。例如,除了 RES /布局(其中你可能现在有上面的布局文件),你可以有 RES /布局大来支持大屏幕。关于这个细节在本指南专题支持多个屏幕和网页的描述它链接到。

The way to support other screen sizes is to have size-specific resource directories. For instance, in addition to res/layout (where you probably now have the above layout file), you could have res/layout-large to support large screens. The details about this are described in the Guide topic Supporting Multiple Screens and the pages that it links to.

您也可以考虑不指定一个确切的大小你的意见,而是让他们填写父母或包裹的内容。如果不适合你的布局工作,你需要指定视图大小,可以使大小变量和 RES /值,<$ C定义大小$ C> RES /价值观大等文件夹。例如,在 RES /布局/ main.xml中你可以有你的布局:

You might also consider not specifying an exact size for your views, but rather let them fill the parent or wrap their content. If that doesn't work for your layout and you need to specify view sizes, you can make the size a variable and define the size in the res/values, res/values-large, etc. folders. For instance, in res/layout/main.xml you could have your layout:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="@dimen/relative_layout_height"
    android:orientation="vertical" >
    <ScrollView android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/scroll_view_height"
        android:background="#86C3C6" >
        <TextView
            android:id="@+id/tvHistory"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#86C3C6"
            android:gravity="right"
            android:focusable="true"
            android:text=""
            android:textColor="#FFFFFF" />
    </ScrollView>
</RelativeLayout>

然后在每个文件夹中的值,你可以有一个 dimens.xml 文件,给予适当的值的相关尺寸。在 RES /价值/ dimens.xml (适用于中等尺寸屏幕):

Then in each values folder you can have a dimens.xml file with the relevant dimensions given appropriate values. In res/values/dimens.xml (for medium-size screens):

<dimen name="relative_layout_height">150dp</dimen>
<dimen name="scroll_view_height">200dp</dimen>

而在 RES /价值观大/ dimens.xml 你会:

<dimen name="relative_layout_height">250dp</dimen>
<dimen name="scroll_view_height">300dp</dimen>

这样的话,你只需要一个布局,它将在维值将由屏幕大小不同进行参数设置。

That way, you would only need one layout and it would be parameterized by dimension values that would vary by screen size.

这篇关于我该如何调整布局和滚动型根据屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆