Android 在九个补丁的内容区域绘制进度条和文本视图
我有一个Android 在九个补丁的内容区域绘制进度条和文本视图,android,styles,nine-patch,Android,Styles,Nine Patch,我有一个RelativeLayout,里面嵌套了一个ProgressBar和一个TextView。RelativeLayout的背景由9patch图像定义,但是子视图没有正确地遵循9patch图像的内容区域,相反,它们只是出现在我的9patch图像中没有定义内容区域时会出现的地方 以下是我的布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.androi
RelativeLayout
,里面嵌套了一个ProgressBar
和一个TextView
。RelativeLayout
的背景由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文件:
9patch image中定义的内容区域与UI组件的位置完全无关,它只定义了如何拉伸图像以填充指定区域。要使UI组件的放置与9patch图像一致,您需要在
相对图中添加适当的填充,我的意思是,左/右/上/下填充大小应与9patch图像的四个边相同。我认为9patch内容区域的全部要点是替换填充?如果不是这样,它会做什么?我知道你现在正在尝试做什么,但根据Android doc():如果视图对象将NinePatch设置为其背景,然后指定视图的文本,它将拉伸自身,以便所有文本只适合由右行和底行(如果包括)指定的区域。。。所以它看起来只适用于视图,而不适用于布局。不过RelativeLayout是视图的一个子类。可能它只适用于文本,而不适用于子视图。