2014-09-24 67 views
0

我的电池部件上的Textview有问题。 有一张图片和它的textview显示%的问题是,我的代码有关文本宽度似乎有问题,因为它只允许每个诗节2个字符,所以它显示为例如。在第一节中为50,在第二节中为%。我如何设置它?另外一个问题:我能以某种方式使文本始终位于底部和中心?我可以使用填充来完成,但它在每个屏幕大小上显示不同。所以无论如何这里是关于文字编辑代码:这里是整个XML文件 -imageview部件上的文字宽度

<?xml version="1.0" encoding="utf-8"?> 
 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:layout_width="wrap_content" 
 
    android:layout_height="wrap_content" 
 
    > 
 

 
    <ImageView 
 
     android:id="@+id/imageView1_widget" 
 
     android:layout_width="200dp" 
 
     android:layout_height="200dp" 
 
     android:scaleType="fitXY" 
 
     android:src="@drawable/bateria50_1" /> 
 

 
    <TextView 
 
     android:id="@+id/textView1_widget" 
 
    
 
     android:layout_height="wrap_content" 
 
     android:layout_alignBottom="@+id/imageView1_widget" 
 
     android:singleLine="true" 
 
     android:layout_gravity="bottom|center_horizontal" 
 
     android:shadowColor="#000000" 
 
     android:shadowDx="2" 
 
     android:shadowDy="2" 
 
     android:shadowRadius="1" 
 
     android:textColor="#FFFFFF" 
 
     android:textSize="15sp" 
 
     android:textStyle="bold" /> 
 

 
</RelativeLayout>

+0

你能告诉我们你的xml文件的其余部分吗? – 2014-09-24 17:57:33

+0

@kristywelsh在帖子中添加了整个xml文件。此外,我添加了来自底部评论的建议代码,以及底部显示的很多文本,并且在一行中它不会居中。 – Osama 2014-09-24 18:40:46

回答

0

对于LinearLayout中:

android:singleLine="true"android:layout_gravity="bottom|center_horizontal"

对于RelativeLayout的:

android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"

+0

感谢您回复@Justin Powell。 'android:singleLine =“true”'working but'android:layout_gravity =“bottom | center_horizo​​ntal”'只有这个工作文本的底部在左下角,你能帮忙吗? – Osama 2014-09-24 18:31:44

+0

@Osama尝试在您的TextView的父视图上放置android:gravity =“center_horizo​​ntal”。 – 2014-09-24 18:48:54

+0

它没有工作,文本是直到在这里左下角是代码的一部分,也许我插错了?我试图在xml文件的开始,但它并不重要,这里是我现在得到的代码的位置部分:' Osama 2014-09-24 19:04:16