【发布时间】:2013-05-04 16:12:33
【问题描述】:
我在布局中有包含元素(按钮、图像等)的应用程序。所有图像都在 ldpi、mdpi、...、xxhdpi 的资源中。如果我在平板电脑 7" (800x480) 上运行应用程序,则元素的尺寸“正确”。但如果我在三星 Galaxy S3 mini 4"(屏幕尺寸 480x800)上运行应用程序,则元素太大。
如何自动减小元素的大小?我尝试将这些行插入清单,但没有成功。
<supports-screens android:xlargeScreens="true" android:smallScreens="true" android:largeScreens="true" android:normalScreens="true"
android:resizeable="true" />
编辑 这是图片。
错了
好
来源:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<ImageButton
android:id="@+id/btnremove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/close"
android:onClick="btnRemoveSong"
android:contentDescription="@string/remove"
android:layout_marginRight="20dp" />
<ImageButton
android:id="@+id/btnUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/move_up"
android:onClick="moveUp"
android:src="@drawable/up" />
<ImageButton
android:id="@+id/btnDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/down"
android:contentDescription="@string/move_down"
android:onClick="moveDown"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/txvCurrentSong"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:singleLine="true"
android:text="@string/play_with"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<ListView
android:id="@+id/listMP3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:layout_weight="1" >
</ListView>
<SeekBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_backward"
android:contentDescription="@string/backward"
android:onClick="backward"
android:layout_marginRight="10dp" />
<ImageButton
android:id="@+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_play"
android:contentDescription="@string/play"
android:onClick="playPause"
android:layout_marginRight="10dp" />
<ImageButton
android:id="@+id/btnStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_stop"
android:contentDescription="@string/stop"
android:onClick="stop"
android:layout_marginRight="10dp" />
<ImageButton
android:id="@+id/btnForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_forward"
android:contentDescription="@string/forward"
android:onClick="forward"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/txvProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:singleLine="true"
android:text="@string/play_status"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
【问题讨论】:
-
请随时发布一些截图来说明您的问题。此外,请随时发布不符合您要求的代码(例如布局资源)。
-
您可以尝试为特定屏幕设计布局,例如 layout-large layout-xlarge 等。您还可以选择为特定屏幕进行设计,例如 layout600w ..
-
通过将布局文件保存在 layout-large 文件夹中进行检查,并且 400X800 的屏幕尺寸只会从 mdpi 文件夹中读取图像,而不是从 hdpi 或 xhdpi 文件夹中读取图像……因此您的布局在屏幕上看起来很大。
-
我只有一个文件夹“布局”。我要创建 layout-large 文件夹吗?如何更改布局大文件夹中的 XML?
-
我创建了 layout-large 和 layout-sw600。但是不知道怎么用?我将 xml 布局复制到这些文件夹,如果我有权利,我必须在这些文件夹上手动更改元素的大小?
标签: java android android-layout dpi screen-size