Center horizontally and/or vertically with 9 patch in Android

六眼飞鱼酱① 提交于 2019-12-12 17:41:55

问题


I can't find a topic talking about my problem which seems to me standard ... And that make me think it is not possible. But I give a try.

I have a RelativeLayout with a 9 patch background (which contain a content area).

Is that possible to center horizontally and/or vertically a TextView inside this RelativeLayout in relation to the content area ?


回答1:


this layout file will do the task

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:gravity="center" >

    <TextView
        android:id="@+id/txtTest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test TextView"
        android:textColor="#000000" >
    </TextView>

</RelativeLayout>

the 9-patch image i used is



来源:https://stackoverflow.com/questions/11502005/center-horizontally-and-or-vertically-with-9-patch-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!