繁体   English   中英

如何在Android中的多种类型的设备上以固定的长宽比背景进行项目布局?

[英]How to make an item layout with a fixed aspect ratio background on multiple types of devices in Android?

我们要做的是:

在此处输入图片说明

在电视屏幕上显示子布局。 电视布局的宽度为match_parent。

我试过的

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:src="@drawable/bg_tv_left" />
    <include
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_marginTop="13dp"
        android:layout_marginLeft="13dp"
        layout="@layout/content" />
</RelativeLayout>

结果:

在此处输入图片说明

您的比例看起来不错,您需要两个孩子都具有相同的layout_width和layout_height才能获得理想的位置,请尝试以下方法:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
<ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:src="@drawable/bg_tv_left" />
<!-- adjust the margin to get the best positioning -->
<include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="13dp"
        android:layout_marginLeft="13dp"
        layout="@layout/content" />
</RelativeLayout>

您可能还需要一种布局来包装它们,具体取决于您的UI设计

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM