1

次のように、RelativeLayout に 2 つの Textview があります。

<RelativeLayout>
   <TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   (*) android:layout_above="@+id/message"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" />
<ScrollView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1">
    <TextView
     android:id="@+id/message"
     android:layout_width="302dp"
     android:layout_height="wrap_content"
     android:layout_above="@+id/editText1"/>
</ScrollView>

Textview id の「メッセージ」をスクロール可能にしたい。そのため、ScrollView 内に追加しましたが、星 (android:layout_above) を配置した場所にエラーが発生しました: @+id/message is not a sibling in the same RelativeLayout

これを修正するにはどうすればよいですか? どんな助けでも大歓迎です

4

5 に答える 5

3

TextView の親が相対レイアウトではなく、ScrollView であるため、このエラーが発生しています。代わりに、ScrollView に id を指定してから、次を使用します。

 android:layout_above="ScrollView id here"
于 2013-08-31T06:51:14.603 に答える
0

ScrollView に id を指定し、ScrollView に対して相対的に配置します

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   (*) android:layout_above="@+id/scroll"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" />
<ScrollView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1"
     android:id="@+id/scroll">
    <TextView
     android:id="@+id/message"
     android:layout_width="302dp"
     android:layout_height="wrap_content"
     android:layout_above="@+id/editText1"/>
</ScrollView>
于 2013-08-31T06:04:37.450 に答える
0

TextView id を ScrollView に移動aboveして、兄弟を参照するようにします。

 <RelativeLayout> <TextView android:id="@+id/title"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" (*)   
 android:layout_above="@+id/message"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true " />       
 <ScrollView   
 android:layout_width="wrap_content"
 android:id="@+id/message
 android:layout_height="wrap_content"    
 android:layout_weight="1"> <TextView  
 android:id="@+id/message"    
 android:layout_width="302dp"/> 
 </ScrollView>`
于 2013-08-31T06:05:14.073 に答える
0

ScrollView を使用して TextView をスクロール可能にしないでください。むしろ、このようにスクロール移動方法を使用します。

TextView message = (TextView) findViewById(R.id.message);
message.setMovementMethod(new ScrollingMovementMethod());
于 2013-08-31T06:08:52.733 に答える