Android:fill_parent和wrap_content不会在所有设备上填满全屏

发布于 2025-01-05 17:41:20 字数 3229 浏览 2 评论 0原文

好吧,我了解所有更高密度的手机和屏幕等等,我的问题是为什么我的背景颜色没有填充整个页面?在我的平板电脑上,它只是一个小框的背景颜色,其余的只是一个块背景。请帮忙。

额外问题:对于更高密度的手机,这是否意味着我必须制作 3 张不同的图像,然后将它们放入不同的文件夹中,或者我可以只制作 1 张图像并将它们放入文件夹中,然后应用程序将处理其他所有事情?我真的不明白我是否控制图像质量/分辨率并且应用程序选择哪一个,或者应用程序是否会自动将图像更改为正确的分辨率和尺寸。

活动文件:

package u.nav.it;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class UNavitActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
    }
}

custom_title.xml:

 <RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:background="#62CFD2"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:src="@drawable/selectiontitle"/>

</RelativeLayout>

custom_style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

     <style name="CustomWindowTitleBackground">
        <item name="android:background">#323331</item>
    </style>

    <style name="CustomTheme" parent="android:Theme">
        <item name="android:windowTitleSize">50dp</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>

</resources>

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="u.nav.it"
    android:versionCode="1"
    android:versionName="1.0" >

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".UNavitActivity" android:theme="@style/CustomTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Ok, i understand all the higher density phones and screens and all that, my problem is why does my background color not fill the entire page? on my tablet it is just a small box of the background color and the rest is just a block background. please help.

BONUS QUESTION: For the higher density phones, does that mean i have to make 3 different images and then put them in the different folders or can i just make 1 image and place them in the folder and then the app will take care of everything else? Really i dont understand exactly if i control my image quality/resolution and the app chooses which one, or if the app will auto change the images to the proper resolution and size.

Activity file:

package u.nav.it;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class UNavitActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
    }
}

custom_title.xml:

 <RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:background="#62CFD2"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:src="@drawable/selectiontitle"/>

</RelativeLayout>

custom_style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

     <style name="CustomWindowTitleBackground">
        <item name="android:background">#323331</item>
    </style>

    <style name="CustomTheme" parent="android:Theme">
        <item name="android:windowTitleSize">50dp</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>

</resources>

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="u.nav.it"
    android:versionCode="1"
    android:versionName="1.0" >

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".UNavitActivity" android:theme="@style/CustomTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红墙和绿瓦 2025-01-12 17:41:20

尝试使用draw9patch图像来帮助扩大未填充的空间

Try using draw9patch image to help expand the unfilled space

贩梦商人 2025-01-12 17:41:20

我只需在清单中添加应用程序支持的屏幕尺寸即可。我怎么感觉自己很蠢。

I simply had to add in my manifest the screen sizes that the app supported. How i feel dumb.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文