Android layout Android图像宽度填充布局
在Android活动中,我想在屏幕上水平放置一个徽标Android layout Android图像宽度填充布局,android-layout,Android Layout,在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"
<?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>
在一个小屏幕中,它填充:
但不是在大屏幕上:
我希望将
layout\u width
设置为fill\u parent
足够,但显然不够。我还必须做什么?尝试使用重量和秤类型
这是修改后的代码。。。请根据您的需要进行更改
<?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>
使用
匹配父项
而不是填充父项
,因为它已被弃用。也可在元素ImageButton
中使用元素的属性layout\u 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>