有没有办法在长屏幕上为 XML 视图设置不同的边距?
一旦屏幕比例非常多样化,我需要为仅长屏幕的视图设置上边距,例如三星 Note II (1280x720) 以正确显示我的 XML。每一个意见都表示赞赏。
您应该为不同的布局使用不同的文件夹名称。喜欢:
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
You will need to create 4 different layouts to support multiple screen sizes.. Refer Android Multiple screen support
Using this you can set margin in larger layout
创建名为layout-xhdpi
内部资源的单独文件夹并在那里定义适当的带有边距的xml,希望它对您有用!
我认为您必须使用相对布局,并将您的图像放入可绘制的 .so 中,以便您的图像能够很好地自行管理。我做了这样的事情: -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/logosmall"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="180dp"
android:layout_height="80dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/logo2" />
</LinearLayout>
</RelativeLayout>