布局的图像背景不是 acroos screen,而是只有一半?

发布于 2024-12-04 01:51:58 字数 1482 浏览 5 评论 0原文

我有一个布局,带有图像、按钮和文本视图。当我将图像设置为背景时,该背景图像只有屏幕的一半,其余部分是黑色的。这种方法在我有一堆东西的其他布局上很好,但这里它只在屏幕的一半上。我怎样才能做到这一点?

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01" 
    android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@drawable/background" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
<ImageView 
    android:layout_width="fill_parent" 
    android:src="@drawable/bonbon" 
    android:id="@+id/imageView1" 
    android:layout_height="wrap_content"/>
<cro.perger.bonbon.MyTextView 
    android:id="@+id/textView1" 
    android:text="Stanje aktiviranih paketa" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"/>
<Button android:layout_height="wrap_content" 
    android:text="Provjeri stanje" 
    android:id="@+id/provjeriStanje" 
    android:layout_width="fill_parent"/>
<TextView android:text=" " 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>

I have a layout, with a image, button and a textview. When I set image as backgroung, this background image is only Half of screen, and the rest is black. This method is good on other layout where i have bunch of stuff, but here it is only on half of the screen. How can i make this right ??

My layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01" 
    android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@drawable/background" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
<ImageView 
    android:layout_width="fill_parent" 
    android:src="@drawable/bonbon" 
    android:id="@+id/imageView1" 
    android:layout_height="wrap_content"/>
<cro.perger.bonbon.MyTextView 
    android:id="@+id/textView1" 
    android:text="Stanje aktiviranih paketa" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"/>
<Button android:layout_height="wrap_content" 
    android:text="Provjeri stanje" 
    android:id="@+id/provjeriStanje" 
    android:layout_width="fill_parent"/>
<TextView android:text=" " 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>

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

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

发布评论

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

评论(3

静谧幽蓝 2024-12-11 01:51:58

您有一个 ScrollView 作为根组件,它的高度定义为“wrap_content”。这很可能是导致您的问题的原因。试试这个版本:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:background="@drawable/background" 
    android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"        
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
<ImageView 
    android:layout_width="fill_parent" 
    android:src="@drawable/bonbon" 
    android:id="@+id/imageView1" 
    android:layout_height="wrap_content"/>
<cro.perger.bonbon.MyTextView 
    android:id="@+id/textView1" 
    android:text="Stanje aktiviranih paketa" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"/>
<Button android:layout_height="wrap_content" 
    android:text="Provjeri stanje" 
    android:id="@+id/provjeriStanje" 
    android:layout_width="fill_parent"/>
<TextView android:text=" " 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>

You have a ScrollView as a root component, it has it's height defined as "wrap_content". This is, most likely, the cause of your issue. Try this version:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:background="@drawable/background" 
    android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"        
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
<ImageView 
    android:layout_width="fill_parent" 
    android:src="@drawable/bonbon" 
    android:id="@+id/imageView1" 
    android:layout_height="wrap_content"/>
<cro.perger.bonbon.MyTextView 
    android:id="@+id/textView1" 
    android:text="Stanje aktiviranih paketa" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"/>
<Button android:layout_height="wrap_content" 
    android:text="Provjeri stanje" 
    android:id="@+id/provjeriStanje" 
    android:layout_width="fill_parent"/>
<TextView android:text=" " 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
最佳男配角 2024-12-11 01:51:58

您的滚动视图正在包装可能没有填满整个屏幕的内容。

将滚动视图标签中的 android:layout_height="wrap_content" 更改为 fill_parent 。

Your scrollview is wrapping the content which probably isn't filling the whole screen.

Change android:layout_height="wrap_content" to fill_parent in the scrollview tag.

随心而道 2024-12-11 01:51:58

现在试试这个...

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01" android:background="@drawable/Path"
    android:layout_height="fill_parent" android:layout_width="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageView android:layout_width="fill_parent" android:src="@drawable/Path"
            android:id="@+id/imageView1" android:layout_height="wrap_content" />

        <Button android:layout_height="wrap_content" android:text="Provjeri stanje"
            android:id="@+id/provjeriStanje" android:layout_width="fill_parent" />
        <TextView android:text=" " android:textAppearance="?android:attr/textAppearanceLarge"
            android:id="@+id/textView2" android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>

Now Try this...

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01" android:background="@drawable/Path"
    android:layout_height="fill_parent" android:layout_width="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageView android:layout_width="fill_parent" android:src="@drawable/Path"
            android:id="@+id/imageView1" android:layout_height="wrap_content" />

        <Button android:layout_height="wrap_content" android:text="Provjeri stanje"
            android:id="@+id/provjeriStanje" android:layout_width="fill_parent" />
        <TextView android:text=" " android:textAppearance="?android:attr/textAppearanceLarge"
            android:id="@+id/textView2" android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文