1

在 Android 活动中,我想放置一个徽标以水平填充屏幕;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:gravity="center"
              android:background="#FF0000"
              android:id="@+id/layout"
>  
    <ImageButton
        android:background="#124644" 
        android:src="@+drawable/androidlogo" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"             
        android:id="@+id/LogoImage" 
    >
    </ImageButton>  
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"        
        android:textColor="#FFFFFF"
        android:background="#000000"
        android:textSize="34sp" 
        android:gravity="center"
        android:typeface="sans"
        android:id="@+id/TitleText"
        android:text="Some Test"
        android:textStyle="bold" 
    >
    </TextView> 
</LinearLayout> 

在一个小屏幕中,它填充:

带 MDPI 屏幕的模拟器

但不是在大屏幕中:

带 MDPI 屏幕的模拟器

我希望设置layout_widthfill_parent足够了,但显然不是。我还必须做什么?

4

2 回答 2

0

尝试使用重量和秤类型。

这是修改后的代码...根据您的需要进行更改

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:gravity="center"
              android:background="#FF0000"
              android:id="@+id/layout"
>  
    <ImageButton
        android:background="#124644" 
        android:src="@drawable/ic_launcher" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"             
        android:id="@+id/LogoImage"
        android:layout_weight=".8" 
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
    >
    </ImageButton>  
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"        
        android:textColor="#FFFFFF"
        android:background="#000000"
        android:textSize="34sp" 
        android:gravity="center"
        android:typeface="sans"
        android:id="@+id/TitleText"
        android:text="Some Test"
        android:textStyle="bold" 
    >
    </TextView> 
</LinearLayout> 
于 2013-07-14T08:08:52.303 回答
0

使用match_parent而不是fill_parent,因为它已被弃用。还在元素中使用元素ImageButton的属性layout_weight适合全屏并且TextView可见:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF0000"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/LogoImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="#124644"
        android:scaleType="fitXY"
        android:src="@drawable/androidlogo" >
    </ImageButton>

    <TextView
        android:id="@+id/TitleText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:gravity="center"
        android:text="Some Test"
        android:textColor="#FFFFFF"
        android:textSize="34sp"
        android:textStyle="bold"
        android:typeface="sans" >
    </TextView>

</LinearLayout>

在此处输入图像描述

于 2013-07-14T08:10:46.333 回答