簡體   English   中英

如何根據用戶在上方的文本視圖中輸入的內容來更改文本視圖的位置?

[英]How can I make a Text View change it's position based on what the user puts in the Text View above?

我有一個簡單的布局,其中包含4個TextView ,其中2個已預填充文本,從頂部開始TextView為數字1和3。 根據用戶點擊的女巫ListItem填充其他兩個。 它們充滿了不同長度的文本,因此大多數情況下,文本會重疊。

如果文本重疊,如何使數字3和4在屏幕上向下定位?

代碼附在下面:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/imageView2"
android:layout_centerHorizontal="true">

    <ImageView
        android:id="@+id/bildeAvGjenstand"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:contentDescription="@string/bildeBesk"
        android:layout_marginBottom="133dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="THIS IS PREFILLED"
        android:textSize="35sp"
        android:layout_above="@+id/gjenstand"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:id="@+id/gjenstand"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""                      
        android:textSize="30sp"
        android:visibility="visible"
        android:layout_above="@+id/bildeAvGjenstand"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="24dp" />

    <TextView
        android:id="@+id/gjoremaal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:text=""   <!-- I want this text view to change position -->
        android:visibility="visible"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView3" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"  <!-- I want this text view to change position -->
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:text="THIS IS PREFILLED"
    android:textSize="35sp" />

看起來結構有點怪異。 我不確定您嘗試做的最終目標是什么,但我想我有個主意。 我在這里為您重新編寫了代碼,該代碼將根據上面文本的大小調整下面的項目。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/imageView2"
    android:layout_centerHorizontal="true">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:text="THIS IS PREFILLED"
        android:textSize="35sp"
        />

    <TextView
        android:id="@+id/gjoremaal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:text="This text changes "
        android:visibility="visible"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView3"
        android:layout_marginBottom="200dp"
        />


    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="THIS IS PREFILLED"
        android:textSize="35sp"
        android:layout_below="@+id/gjoremaal"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:id="@+id/gjenstand"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This text changes"
        android:textSize="30sp"
        android:visibility="visible"
        android:layout_below="@+id/textView2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="24dp" />

    <ImageView
        android:id="@+id/bildeAvGjenstand"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:contentDescription="sample"
        android:layout_below="@+id/gjenstand"
        android:layout_centerHorizontal="true" />
    </RelativeLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM