我只想制作一个 ImageView 作为我的标题栏...它应该只填充他的父线性布局...显然它没有。
有什么方法可以告诉scaleType只适合它的父布局吗? (XML中的最佳解决方案)我看到这是一个编程解决方案,它将scaleType设置为“填充”...但似乎没有匹配的xml属性,或者我没有看到它?
<?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="wrap_content">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:id="@+id/linearlayoutmain">
<ImageView
android:layout_marginTop="0dp"
android:src="@drawable/headbar"
android:id="@+id/mainheadbar"
android:scaleType="fitStart"
android:paddingTop="0dp"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="7"
android:layout_below="@id/linearlayoutmain">
</LinearLayout>
</RelativeLayout>
对此有什么想法/解决方案吗?我认为我不需要介意纵横比,因为我对整个事情进行了 9 次修补..所以它不应该介意。
编辑:当我使用 ImageBUtton 而不是 imageview 时,它似乎工作得更好...但是,我在较小尺寸的屏幕上遇到了问题...他们似乎不介意我的 9patching...哈哈
最佳答案
一般需要使用三种类型的布局
布局 hdpi
布局-mdpi
布局-ldpi
一般来说,您还需要使用三个值布局
值-hdpi
值-mdpi
值-ldpi
在这里,我解释了您必须为所有设备 HDPI、MDPI 等执行的 LDPI 设备 header
例如,将图像作为标题的简单 xml:layout-ldpi - 标题
<?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="50px"
android:orientation="horizontal" >
<ImageView android:id="@+id/header_main_title" android:layout_marginTop="10dip"
android:layout_width="wrap_content" android:layout_height="50dip"
android:background="@drawable/header_image"
android:layout_centerHorizontal="true" android:layout_marginRight="10dip"
/>
类似的values-ldpi包含
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">50px</item>
<item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground
</item>
</style>
</resources>
对于 Styles.xml 类似:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="WindowTitleBackground" parent="android:WindowTitleBackground">
<item name="android:background">@android:color/transparent</item>
</style>
在您的 Manifest.xml 中包含此行:
<application android:icon="@drawable/vmi_icon" android:label="@string/app_name" android:theme="@style/MyTheme" >
将 Styles.xml 和 Themes.xml 放入 values-ldpi 文件夹
我显示了 ldpi 设备的 header ,您需要为 MDPI 和 HDPI 设备创建类似的 header
应该在这一行中进行所有更改
如果是 HDPI:
<item name="android:windowTitleSize">100px</item>
如果是 Mdpi :
<item name="android:windowTitleSize">70px</item>
与 header.xml 类似:
如果是 HDPI:
android:layout_height="100px"
如果是 Mdpi :
android:layout_height="70px"
关于java - ImageView ("headbar")不同的屏幕等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7030227/