【问题标题】:Draw progress bar and textview in content area of nine patch在九个补丁的内容区绘制进度条和textview
【发布时间】:2012-04-26 02:59:41
【问题描述】:

我有一个RelativeLayout,其中嵌套了一个ProgressBar 和一个TextViewRelativeLayout 的背景由 9patch 图像定义,但子视图没有正确遵循 9patch 图像的内容区域,相反,如果我在 9patch 图像中没有定义内容区域,它们只会出现在它们出现的位置.

这是我的布局:

<?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:gravity="center_horizontal"
    android:orientation="vertical"
    android:background="@+drawable/loading_screen" 
    android:padding="0dip" >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_above="@+id/progressBar1"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/loading"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/black" />

</RelativeLayout>

这是我的 9patch 文件:

【问题讨论】:

    标签: android styles nine-patch


    【解决方案1】:

    9patch 图像中定义的内容区域与 UI 组件的位置完全无关,它只是定义了应该如何拉伸图像以填充指定区域。为了使 UI 组件的放置与 9patch 图像一致,您需要为 RelativeLayout 添加适当的填充,我的意思是左/右/上/下填充大小应该与 9patch 图像的四个边相同.

    【讨论】:

    • 我认为 9patch 的内容区域的重点是替换填充?如果不是这样,它会做什么?
    • 我知道您现在要做什么,但根据 Android 文档 (developer.android.com/guide/topics/graphics/…):如果 View 对象 设置 NinePatch作为它的背景,然后指定视图的文本,它会自行拉伸,以便所有文本仅适合右线和底线指定的区域(如果包括)......所以它看起来只适用于视图,而不是布局。
    • RelativeLayout 是 View 的子类。也许它只适用于文本而不是子视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多