相关疑难解决方法(0)

如何使应用程序的背景图像重复

我在我的应用程序中设置了背景图像,但背景图像很小,我想重复它并填写整个屏幕.我该怎么办?

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg"
    android:tileMode="repeat">
Run Code Online (Sandbox Code Playgroud)

layout android image

312
推荐指数
4
解决办法
20万
查看次数

ScrollView中的视图与配置的父级不匹配

我有一个ViewPager和一个带有标签的ActionBar.其中一个选项卡有一个ListView,当我点击该ListView中的一个选项时,我添加了一个子Fragment,它是该行的详细视图.

该详细视图是一个ScrollView,里面有一个LinearLayout.ScrollView match_parent/match_parent和它里面的LinearLayout是width=match_parentheight=wrap_content.在手机大小的模拟器上,详细视图根据需要填充屏幕,但在平板电脑上,详细视图仅覆盖屏幕宽度的一部分...即使ScrollView的宽度和LinearLayout的宽度为两个match_parent.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootView" style="@style/RootScrollView">

    <LinearLayout android:id="@+id/scrollContentView" style="@style/ScrollViewContent">
        ...
    </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

这是滚动视图的样式:

<style name="RootScrollView">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

以下是LinearLayout内容的样式:

<style name="ScrollViewContent">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:paddingLeft">15dp</item>
    <item name="android:paddingRight">15dp</item>
    <item name="android:orientation">vertical</item>
    <item name="android:background">@drawable/image_legal_paper_tile</item>
</style>
Run Code Online (Sandbox Code Playgroud)

内容视图有一个重复的背景image_legal_paper_tile,这是:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/legal_paper_tile" 
    android:gravity="fill_horizontal"
    android:tileMode="repeat" />
Run Code Online (Sandbox Code Playgroud)

因此,图像应水平拉伸并重复,从而在背景中创建黄色合法纸垫.

这就是列表和详细视图看起来像手机模拟器:

在此输入图像描述

这是真实平板电脑上的列表和详细视图.黄色的合法垫片段应该填满整个屏幕的宽度,但事实并非如此.

在此输入图像描述

编辑:

这是背景法律文件图像:

在此输入图像描述

它宽320像素.手机模拟器宽480像素,图像正确拉伸,以填充屏幕宽度.然后按预期垂直重复.但是,它不会拉伸以填充平板电脑上的屏幕宽度.

平板电脑上显示的宽度不是图像的原始大小,因为它会根据内容更改大小.片段首次加载时,它是一个宽度.然后我填写字段并执行计算,在内容视图的底部添加一些文本.该文本比现有内容更宽,因此在设置文本时,片段的宽度会增加以支持更宽的内容.

所以,简而言之,不,平板电脑上的宽度不是图像的原始尺寸.图像是伸展的,只是没有一直伸展.

android android-fragments

30
推荐指数
3
解决办法
2万
查看次数

drawable中的tileMode重复将无法正常工作

我有这个可绘制的资源:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/bg_stripe"
    android:tileMode="repeat"
    android:antialias="true"
    android:dither="false"
    android:filter="false"
    android:gravity="left"
/>
Run Code Online (Sandbox Code Playgroud)

用作背景:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_world_locked" >
Run Code Online (Sandbox Code Playgroud)

有时候一切都运行良好,有时候不行(可绘制资源以实际的小尺寸显示而不重复).为什么?这是一个Android bug?我在我的HTC Desire Android 2.3上运行它.

android

6
推荐指数
1
解决办法
7830
查看次数

标签 统计

android ×3

android-fragments ×1

image ×1

layout ×1