2013-08-31 40 views
1

我有一個RelativeLayout的2個Textviews這樣的:相對佈局錯誤。 「不是兄弟」

<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'd 「消息」 是滾動的。所以我添加它在一個滾動視圖,但我已經把一個明星(android:layout_above)我得到的錯誤:@ + ID /消息是不是兄弟在同一RelativeLayout

我該如何解決這個問題?任何幫助表示讚賞

回答

3

你必須從

android:layout_above="@+id/message"

刪除「+」

android:layout_above="@id/message" 

而且使用的TextView的滾動方法,而不是首先小號crollview

<TextView 
android:scrollbars="vertical" // Add this to your TextView in .xml file 
android:maxLines="ANY_INTEGER" // also add the maximum line 
android:id="@+id/message" 
android:layout_width="302dp" 
android:layout_height="wrap_content" 
android:layout_above="@id/editText1"/> 

然後在您的.java文件中爲您的textview添加以下方法。

TextView message = (TextView) findViewById(R.id.message); 
message.setMovementMethod(new ScrollingMovementMethod()); 
+0

它的作品有「+」,但你寫的是正確的。我們應該只在給id時使用+,而不是在使用時使用+。 –

0

給ID您滾動型和相對對準了滾動

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

移動你的TextView id來了滾動,這樣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>` 
0

不要使用滾動視圖,使您的TextView滾動。而是像這樣使用滾動移動方法。

TextView message = (TextView) findViewById(R.id.message); 
message.setMovementMethod(new ScrollingMovementMethod()); 
3

它給出了這個錯誤,因爲你的TextView的父母不是相對佈局,它是ScrollView。而是給你的ScrollView一個ID然後使用:

android:layout_above="ScrollView id here"