我要如何插入一个圆角矩形,在和Android视图中的文字? [英] How do I insert text inside a rounded rectangle in and Android view?

查看:127
本文介绍了我要如何插入一个圆角矩形,在和Android视图中的文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下观点,即我需要创建。我有以下的XML,但文字不显示,高度填充包装内容的整个父呢?创建下面的截图将AP preciated任何帮助。

I have the below view that I need to create. I have the following XML, but the text does not show up and the height fills the entire parent instead of wrapping the content? Any help on creating the below screenshot would be appreciated.

playing.xml

playing.xml

<View 
    android:background="@drawable/rounded_edges"
    android:text="Current Track" 
    android:textColor="#FFFFFF"
    android:id="@+id/current_track"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:editable="false">
</View>

rounded_edges.xml

rounded_edges.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <solid android:color="#1F1F1F"/>
  <corners android:radius="5px"/>
  <padding android:left="20dp" android:top="20dp" android:right="20dp" android:bottom="20dp" /> 
</shape>

推荐答案

首先,你必须创建圆边一个XML文件,然后创建一个线性布局,并设置圆边在回地面,然后动态地添加文本查看到特定的线性布局。

First you have to create a one xml file for rounded edges, then create a one linear layout and set that rounded edges in that back ground and then dynamically add text view to that particular linear layout .

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/Your runded edges xml file"
            android:orientation="vertical"
            android:layout_marginRight="10dp"   
            android:id="@+id/linearLayout">

</LinearLayout>]

下面我重视我的圆边的xml文件

Here i attached my rounded edge xml file

<?xml version="1.0" encoding="UTF-8"?> 

        

<stroke android:width="1dp"
        android:color="#ababab"
        />

<padding android:left="1dp"
         android:top="1dp"
         android:right="1dp"
         android:bottom="1dp"
         /> 

<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
 android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 

这篇关于我要如何插入一个圆角矩形,在和Android视图中的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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