Android不调整大小?
我正在Eclipse的4英寸模拟器上开发我的应用程序。我的手机是一款4.6英寸的安卓设备,当我在上面测试时,内容无法正确缩放 它看起来像是手机将内容保持在相同的大小,它只是将所有内容向上移动,并将多余的空间留空 从我所读到的,我认为它应该保持相同的布局,只要我使用dp而不是in。这是否意味着我的图像也需要dp 有什么建议吗 编辑: 下面是一些代码:Android不调整大小?,android,layout,scaling,Android,Layout,Scaling,我正在Eclipse的4英寸模拟器上开发我的应用程序。我的手机是一款4.6英寸的安卓设备,当我在上面测试时,内容无法正确缩放 它看起来像是手机将内容保持在相同的大小,它只是将所有内容向上移动,并将多余的空间留空 从我所读到的,我认为它应该保持相同的布局,只要我使用dp而不是in。这是否意味着我的图像也需要dp 有什么建议吗 编辑: 下面是一些代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tfltestbg2"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="@drawable/tfl_header_port"
android:gravity = "center_horizontal"
android:layout_gravity = "center_horizontal"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:layout_gravity = "center"
android:gravity = "center"
>
<Button
android:id="@+id/buttonTakePic"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:gravity = "left"
android:background="@drawable/takepic_button" />
<Button
android:id="@+id/mMegaGalleryButton"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity = "center"
android:background="@drawable/add_fotos" />
<Button
android:id="@+id/mGalleryButton"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity = "right"
android:background="@drawable/selectpic"
android:paddingLeft = "10dp"
android:paddingRight = "10dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/image_container"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center"
android:background="@drawable/outline_box"
android:gravity="center">
<FrameLayout
android:layout_width = "match_parent"
android:layout_height = "fill_parent"
android:gravity = "center"
android:layout_gravity = "center">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background = "@drawable/blank"
android:gravity="center" />
<ImageView
android:id="@+id/picsImage"
android:layout_width = "100dp"
android:layout_height = "100dp"
android:layout_gravity="center"
android:gravity="center"
android:background = "@drawable/picture_box"/>
</FrameLayout>
</LinearLayout>
<Button
android:id="@+id/mEditButton"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="@drawable/edit_pic_button" />
<View
android:layout_width="match_parent"
android:layout_height="10dp" />
<Button
android:id="@+id/buttonUploadPic"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="@drawable/upload_pic_button" />
</LinearLayout>
使用相对布局,而不是线性布局,如果使用应用程序处理不同大小的屏幕,则不要使用硬编码尺寸,如40dp、50dp
布局中的问题是在错误的位置使用了固定值!相反,您应该在按钮中使用
android:layout\u width=“100dp”
(在水平布局中),使用android:layout\u width=“fill\u parent”
您必须为该按钮的
layout\u weight
设置非零值,以便它们可以在此布局中与其他同级共享空间。将固定dp转换为重量的最简单方法:
更改此项:
android:layout_width=“100dp”
为此:
android:layout_width=“0dp”
android:layout_weight=“100”
对所有按钮都执行此操作,它们将与4中的完全相同“在任何屏幕上都可以完美缩放。确实很长,但我会继续发布它。不要在ImageView中使用背景,请使用src。”。您的前3个按钮的dp已修复,这意味着它们不会占用所有可用空间。用重量来做这个。所有一级物品都有固定的dp高度,这意味着它们不会占据所有可用的高度。使用重量。好的,我试着远离重量,因为我不知道它们做了什么,所以我会查阅一些关于它们的教程。谢谢你的帮助!读这个