gpt4 book ai didi

android - 如何适应布局背景图像

转载 作者:太空狗 更新时间:2023-10-29 13:34:39 27 4
gpt4 key购买 nike

我想为两个屏幕尺寸不同但密度相同的设备使用一张图片 ( 1280x800 )。

屏幕尺寸为 1280x800320x480

图像是 9-patch (有内容区域)。我想使用图像作为一行的背景,它有一个 TextView 。并且不要对文本使用手动填充(我想使用内容区域)。

如果我使用这个 xml:

<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:foo="http://schemas.android.com/apk/res/pak.name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/menu_selector"
android:gravity="right|center_vertical">

<pack.name.TextViewPlus
android:id="@+id/menutext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#3D1E00"
android:textSize="@dimen/TitleNormalM"
foo:customFont="font.ttf"
android:text="blah blah"/>

模拟器的输出是:

http://ivm.neru9.com/pic/2ccf95a7f2e1.png

如果我使用这个 xml:

<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:foo="http://schemas.android.com/apk/res/pack.name."
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="15dp"
android:paddingLeft="15dp">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@layout/menu_selector"
android:scaleType="fitCenter"
/>

<pack.name..TextViewPlus
android:id="@+id/menutext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#3D1E00"
android:textSize="@dimen/TitleNormalM"
foo:customFont="font.ttf"
android:gravity="right|center_vertical"
android:text="blah blah blah"/>

输出是:

http://ivm.neru9.com/pic/f20f7f5d2e7a.png

这是 listview xml(我认为对于这个问题并不重要):

<ListView
android:id = "@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@null"
android:dividerHeight="3dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent"
/>

及其位于布局文件夹中的 menu_selector xml 代码:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed -->
<item android:state_pressed="true" android:drawable="@drawable/bg_menu_pressed" />
<!-- selected -->
<item android:state_selected="true" android:drawable="@drawable/bg_menu_focused" />
<!-- selected & pressed -->
<item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/bg_menu_pressed" />
<!-- default -->
<item android:drawable="@drawable/bg_menu" />

最佳答案

check out this project ,

基本上问题是你的 9 补丁图像,我只是修改你的图像以获得你问题的期望性能。

我会建议您使用 bg_menu277x77 用于 1280x800 和 bg_menu144x40 用于上面链接项目的 320x480 分辨率。只是为了测试,您可以交换两个图像的分辨率并尝试。

下面我会尽力解释 9 个补丁图像,其他很棒的教程和信息你可以谷歌它:)

enter image description here

关于android - 如何适应布局背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11932319/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com