在 Android 中重新定位文本

Reposition text in Android

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

代码:

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

所以它有点居中,但只是两个文本视图作为一个整体居中,而不是一个在页面中间。

编辑:还有可能只加粗 'GDPR Statement' 而不是文本的其余部分吗?

您可以将两个 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>

最佳