【问题标题】:Reposition text in Android在 Android 中重新定位文本
【发布时间】:2019-03-29 09:55:22
【问题描述】:

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

代码:

<?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 声明”而不加粗文本的其余部分吗?

【问题讨论】:

    标签: android android-layout textview


    【解决方案1】:

    您可以将两个AppCompatTextView 包装在一个垂直方向的LinearLayout 中以满足您的需求。 FrameLayout hee 似乎没用。此外,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 文件中使用 &lt;b&gt;GDPRStatement&lt;/b&gt;,如下所示:

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

    最好的

    【讨论】:

      猜你喜欢
      • 2013-06-21
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多