![](/img/trans.png)
[英]Automatically resize JInternalFrame according to the screen resolution
[英]How can i resize the layout and scrollview according to screen resolution
我設置屏幕分辨率為480x800的布局和滾動視圖。 如何與其他屏幕分辨率兼容? 這是我的代碼。 請幫我。
<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>
請幫助我通過程序設置布局,滾動視圖和文本大小
首先,Android不支持“屏幕分辨率”的概念。 有屏幕尺寸和屏幕(或像素)密度。 由於您已經在使用密度無關的像素(dp),因此我想您的問題是關於支持不同的屏幕尺寸的。
支持其他屏幕尺寸的方法是擁有特定於尺寸的資源目錄。 例如,除了res/layout
(您現在可能已經有了上面的布局文件)之外,您還可以使用res/layout-large
來支持大屏幕。 有關詳細信息,請參見《指南》主題“ 支持多個屏幕”及其鏈接到的頁面。
您可能還考慮不為視圖指定確切的大小,而是讓它們填充父級或包裝其內容。 如果這對於您的布局不起作用,並且您需要指定視圖大小,則可以將大小設置為變量,然后在res/values
, res/values-large
等文件夾中定義大小。 例如,在res/layout/main.xml
您可以進行布局:
<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/values/dimens.xml
(適用於中型屏幕):
<dimen name="relative_layout_height">150dp</dimen>
<dimen name="scroll_view_height">200dp</dimen>
在res/values-large/dimens.xml
您將具有:
<dimen name="relative_layout_height">250dp</dimen>
<dimen name="scroll_view_height">300dp</dimen>
這樣,您只需要一種布局,並且可以通過隨屏幕尺寸而變化的尺寸值進行參數化。
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" //would fill what ever size it wud be.
android:orientation="vertical" >
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" //would fill what ever size it wud be.
android:background="#86C3C6" >
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.