ImageView(“headbar”)不同的屏幕等

时间:2011-08-11 17:27:05

标签: java android xml layout

我只想将ImageView作为我的标题栏...它应该只填写他的父线性布局......显然它没有。

有没有办法告诉scaleType只是为了适应它的父布局? (XML中的最佳解决方案)我看到这是一个编程解决方案,它将scaleType设置为“fill”...但似乎没有匹配的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>

关于它的任何想法/解决方案?我以为我不需要考虑宽高比,因为我对整个事情做了补丁..所以它不应该介意。

编辑:当我使用ImageBUtton而不是imageview时它似乎工作得更好...但是,我在较低尺寸的屏幕上遇到问题......他们似乎不介意我的9个修补...大声笑

1 个答案:

答案 0 :(得分:1)

您通常需要使用三种类型的布局

  1. 布局HDPI

  2. 布局MDPI

  3. 布局LDPI

  4. 您还需要使用三种值布局

    1. 值-HDPI

    2. 值-MDPI

    3. 值-LDPI

    4. 在这里,我将解释您必须为所有设备HDPI,MDPI等做的LDPI设备标题

      例如,具有Image为Header的简单xml:layout-ldpi - Header

      <?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" 
                       />
      

      同样,value-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设备的标头,同样需要创建 MDPI HDPI 设备

      应该在所有

      的这一行中进行更改

      如果它是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"
      

      如果您需要进一步澄清,请与我们联系。 谢谢Venky。

相关问题