在Android中重新定位文本

时间:2019-03-29 09:55:23

标签: android android-layout textview

如何更改要显示的文本的位置,该位置在图像上突出显示(蓝色)。

The wanted display

代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.HomeFragment">

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/darekeapp_info"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:text="@string/darekeapp_info"
        android:textSize="18sp"
        android:gravity="center"
        android:textColor="@android:color/black" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/gdpr_statement"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginBottom="50dp"
        android:gravity="center"
        android:text="@string/gdpr_statement"
        android:textColor="@android:color/black" />
</FrameLayout>

所以它有点居中,但是整个两个textview都居中,而不是一个居于页面中间。

编辑:还有可能仅将粗体的“ GDPR声明”而不是文本的其余部分吗?

1 个答案:

答案 0 :(得分:1)

您可以将两个AppCompatTextView包裹在LinearLayout中,并垂直放置以满足您的需求。 FrameLayout嘻嘻似乎没用。此外,gravitylayout_gravity不适用于这种版式。您应该这样做:

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/darekeapp_info"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/darekeapp_info"
        android:textSize="18sp"
        android:textColor="@android:color/black" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/gdpr_statement"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/gdpr_statement"
        android:textColor="@android:color/black" />

</LinearLayout>

如果要加粗GDPR,则应在strings.xml文件中使用<b>GDPRStatement</b>,如下所示:

<string name="gdpr_statement"><b>GDPRStatement</b> - the rest of your text</string>

最佳