2016-01-16 4 views
0

У меня есть пустое действие, которое содержит много текстового вида, поэтому я хочу использовать scrollview, но всякий раз, когда я его использую, текстовые представления смещаются от их предварительно назначенного положения к вершине. Before adding ScrollView и After adding ScrollView вот код XMLScrollview Realigns textView

<?xml version="1.0" encoding="utf-8"?> 


<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="OFF" 
    android:id="@+id/button" 
    android:onClick="torchToggle" 
    android:layout_below="@+id/textView" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="71dp" 
    android:background="#cdc6c6" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Torch" 
    android:id="@+id/textView" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:textColor="#e8d9d9" /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:id="@+id/textView2" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" 
    android:textColor="#dacece" 
    android:text="#Error In display" /> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:id="@+id/textView3" 
    android:layout_below="@+id/textView2" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="83dp" 
    android:textColor="#cdc0c0" 
    android:text="#Error in display" /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:id="@+id/textView4" 
    android:textColor="#f3ef7a" 
    android:layout_below="@+id/textView3" 
    android:layout_centerHorizontal="true" 
    android:text="#Error in display" /> 

<ProgressBar 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/progressBar" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" /> 

<Button 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="next" 
    android:id="@+id/button2" 
    android:layout_alignTop="@+id/button" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:nestedScrollingEnabled="false" 
    android:onClick="nextActivity" /> 



</RelativeLayout> 
</ScrollView> 

ответ

2

Высота вашего RelativeLayout падает обратно wrap_content, когда внутри ScrollView как виртуальная высота ScrollView бесконечна и match_parent не имеет смысла.

Вы можете попробовать добавить android:fillViewport="true" в ScrollView. Это даст RelativeLayout минимальную высоту match_parent. Вы должны изменить RelativeLayout's layout_height на wrap_content.

Смежные вопросы