在Android中使用9个补丁水平和/或垂直居中 [英] Center horizontally and/or vertically with 9 patch in Android

查看:90
本文介绍了在Android中使用9个补丁水平和/或垂直居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到谈论我的问题的话题,这在我看来是标准的……这使我认为这是不可能的.但我尝试一下.

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.

我有一个带有9个补丁背景的RelativeLayout(其中包含一个内容区域).

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

是否可以相对于内容区域在此RelativeLayout中将TextView水平和/或垂直居中?

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

推荐答案

此布局文件将完成任务

<?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>

我使用的9补丁图像是

这篇关于在Android中使用9个补丁水平和/或垂直居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆