android - 如何将文本放置在底部中心

标签 android textview

如何将文本放置在底部中心?

我的实现

 @Override
            protected void onDraw(Canvas canvas) {

                Paint strokePaint = new Paint();
                strokePaint.setARGB(255, 0, 0, 0);
                //strokePaint.setTextAlign(Paint.Align.CENTER);


                strokePaint.setTextSize(20);
                strokePaint.setTypeface(Typeface.DEFAULT_BOLD);
                strokePaint.setStyle(Paint.Style.STROKE);
                strokePaint.setStrokeWidth(5);

                Paint textPaint = new Paint();
                textPaint.setARGB(255, 255, 255, 255);
                //textPaint.setTextAlign(Paint.Align.CENTER);
                textPaint.setTextSize(20);
                textPaint.setTypeface(Typeface.DEFAULT_BOLD);

                canvas.drawText("Some Text", 100, 100, strokePaint);
                canvas.drawText("Some Text", 100, 100, textPaint);

            }
<ImageView
    android:id="@+id/myImageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/img_1" />

<vbright.usanin.salesRegion.Text.TextViewOutline
    android:id="@+id/myImageViewText"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignBottom="@+id/myImageView"
    android:layout_alignLeft="@+id/myImageView"
    android:layout_alignRight="@+id/myImageView"
    android:layout_alignTop="@+id/myImageView" />

enter image description here

最佳答案

使用RelativeLayout将文本放置在您想要的任何位置。在你的情况下android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"做魔术。

<RelativeLayout  
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 
android:paddingTop="5dip" > 

  <TextView
        android:id="@+id/txtExistingService"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true">
 </TextView>

希望能帮助到你。

关于android - 如何将文本放置在底部中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13230262/

相关文章:

android - AlertDialog 被空 onClick 关闭

android - 在 Fragment 类中显示 ProgressDialog

javascript - android textview 中带有 &lt;style&gt; 标签和样式的 Html 字符串

android - 如何获取 TextView 中每一行的字符数?

android - 放置错误消息时 TextView 中的文本正在更改

android - GCM - pubSub.subscribe 不工作

Android Asus 七寸 hdpi 平板布局问题

android - 在 kotlin 中使用房间作为单例

java - 获取选定的回收 View 的文本(使用 FireBase)

android - 当我从 textview 插入值时,为什么我的字符串不能按我想要的方式排序?