2016-03-02 2 views
0

Я использую ScrollView. Хотя я работал с ним раньше, я вдруг столкнулся с проблемой. В какой-то момент содержимое начинает расти.Содержание прокрутки вверх вверх

В моей AndroidStudio .xml файл все выглядит отлично:

enter image description here

Но на моем устройстве я получаю это:

enter image description here

Как вы можете видеть, "Заметки идут сюда" текст переместился вверх. Я нажал кнопку, часть ее обрезана.

Мой .xml код выглядит следующим образом:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/mainLayout"> 

.... 

    </RelativeLayout> 
</ScrollView> 

И моя деятельность:

public class ProfileInfo extends Activity { 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.profile_info); 


    } 

} 

[UPDATE]

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroll" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/mainLayout"> 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Profile" 
      android:id="@+id/ProfHead" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="20dp" 
      android:layout_centerHorizontal="true" 
      /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:scaleType="fitCenter" 
      android:id="@+id/imageProfile" 
      android:src="@drawable/profile_icon" 
      android:layout_marginTop="20dp" 
      android:layout_marginBottom="20dp" 
      android:layout_above="@+id/contactsBtn" 
      android:layout_below="@+id/ProfHead" /> 



     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Home Phone a" 
      android:id="@+id/anchor1" 
      android:visibility="invisible" 
      android:layout_alignLeft="@+id/nameHead" 
      android:layout_alignStart="@+id/nameHead" /> 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Name" 
      android:id="@+id/nameHead" 
      android:layout_below="@+id/patProfHead" 
      android:layout_marginTop="200dp" 
      android:layout_marginLeft="20dp" 
      android:layout_alignParentLeft="true"/> 


     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Contacts >" 
      android:id="@+id/contactsBtn" 
      android:layout_above="@+id/editName" 
      android:layout_toRightOf="@id/anchor1"/> 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:id="@+id/editName" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_below="@+id/nameHead" 
      android:layout_marginLeft="20dp" 
      android:layout_alignParentLeft="true" 
      android:text="Name"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Surname" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_marginRight="20dp" 
      android:id="@+id/editSurname" 
      android:layout_below="@+id/nameHead" 
      android:layout_toRightOf="@id/editName"/> 



     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Sex" 
      android:id="@+id/sexHead" 
      android:layout_marginTop="10dp" 
      android:layout_below="@id/editName" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="20dp" 

      /> 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/anchor1" 
      android:text="Sex" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_alignBottom="@id/sexHead" 
      android:id="@+id/radioGroup"> 

     </TextView> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Age" 
      android:id="@+id/ageHead" 
      android:layout_below="@id/sexHead" 
      android:layout_marginTop="10dp" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="20dp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:text="Age" 
      android:id="@+id/editAge" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_toRightOf="@id/anchor1" 
      android:layout_alignBaseline="@id/ageHead"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="DOB" 
      android:id="@+id/dobHead" 
      android:layout_below="@id/ageHead" 
      android:layout_marginTop="10dp" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="20dp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:text="DOB" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:id="@+id/editDob" 
      android:layout_toRightOf="@id/anchor1" 
      android:layout_alignBaseline="@id/dobHead"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Height" 
      android:id="@+id/heightHead" 
      android:layout_below="@id/dobHead" 
      android:layout_marginTop="10dp" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="20dp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Height" 
      android:id="@+id/editHeight" 
      android:layout_toRightOf="@id/anchor1" 
      android:layout_alignBaseline="@id/heightHead"/> 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Weight" 
      android:id="@+id/weightHead" 
      android:layout_below="@id/heightHead" 
      android:layout_marginTop="10dp" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="20dp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Weight" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:id="@+id/editWeight" 
      android:layout_toRightOf="@id/anchor1" 
       android:layout_marginRight="20dp" 
       android:layout_alignBaseline="@id/weightHead"/> 


      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Notes" 
       android:id="@+id/notesHead" 
       android:layout_below="@id/weightHead" 
       android:layout_marginTop="10dp" 
       android:layout_alignParentLeft="true" 
       android:layout_marginLeft="20dp"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Template >" 
     android:id="@+id/notesBtn" 
     android:layout_alignBaseline="@id/notesHead" 
     android:layout_toRightOf="@id/anchor1"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:id="@+id/editNotes" 
     android:layout_below="@+id/notesBtn" 
     android:layout_marginLeft="20dp" 
     android:text="The notes go here" 
     android:layout_marginRight="20dp" 
     android:layout_alignParentLeft="true" /> 

    </RelativeLayout> 
</ScrollView> 
+0

Я не вижу ссылки на «Notes go here» в Activity или xml. Трудно сказать, почему это не то место, где вы этого хотите. – DSlomer64

+0

вместо '....' есть TextViews и Buttons. Я все там определяю. в .xml –

ответ

0

Выпуск 1: Ваше мнение внутри ScrollView не должен иметь родительский ответ высоты. Это поражает цель ScrollView. вид имеет собственный размер, а свиток содержит его (обычно внутренний вид больше и ScrollView прокручивает его). Попробуйте вместо этого использовать содержимое оболочки.

выпуск 2: ваш ScrollView имеет height = "wrap_content". Это ошибка, ScrollView не регулирует ее высоту в соответствии с содержимым. попробуйте либо дать ему явную высоту, либо дать ему height = "match_parent".

выпуск 3: то, что вы видите как текст поверх другого содержимого, является результатом использования RelativeLayout. в RelativeLayout виды лежат поверх каждого другого относительно верхнего/нижнего/левого/правого родительского. Если вы не хотите, чтобы они перекрывались, используйте LinearLayout вместо RelativeLayout или используйте LinearLayout с несколькими дочерними элементами внутри вашего RelativeLayout.

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/mainLayout"> 
    </LinearLayout> 
</ScrollView> 
+0

Не помогло. Все одинаково. –

+0

Можете ли вы разместить весь xml? – TacoEater

+0

отправил его в ** [ОБНОВЛЕНИЕ] ** раздел –

1

использование linear расположение вертикальный первый. то в каждой строке используйте линейный макет по горизонтали.

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:id="@+id/mainLayout"> 

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:id="@+id/mainLayout"> 
      //here put your code for each line. 
     </LinearLayout> 
     //then again use a linear layout horizontal for next line 
     . 
     . 
     . 
     . 
    </LinearLayout> 
</ScrollView> 
1

Это может быть почти то, что вы хотите. Вы можете настроить его немного, чтобы достичь того, чего хотите.

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroll" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="center"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Profile" 
       android:id="@+id/ProfHead" 
       android:layout_marginTop="20dp" 
       /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="center"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:scaleType="fitCenter" 
       android:id="@+id/imageProfile" 
       android:src="@drawable/profile_icon" 
       android:layout_marginTop="20dp" 
       android:layout_marginBottom="20dp" /> 
     </LinearLayout> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Contacts >" 
      android:id="@+id/contactsBtn" 
      android:layout_gravity="center"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Home Phone a" 
      android:id="@+id/anchor1" 
      android:visibility="invisible" 
      android:layout_alignLeft="@+id/nameHead" 
      android:layout_alignStart="@+id/nameHead" /> 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Name" 
      android:id="@+id/nameHead" 
      android:layout_marginLeft="20dp"/> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="20dp" 
       android:id="@+id/editName" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:layout_marginLeft="20dp" 
       android:text="Name"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Surname" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:layout_marginRight="20dp" 
       android:id="@+id/editSurname"/> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Sex" 
       android:layout_marginRight="20dp" 
       android:id="@+id/sexHead" 
       android:layout_marginTop="10dp" 
       android:layout_marginLeft="20dp" 

       /> 


      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Sex" 
       android:layout_marginTop="10dp" 
       android:layout_marginLeft="20dp" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:id="@+id/radioGroup"> 

      </TextView> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Age" 
       android:id="@+id/ageHead" 
       android:layout_marginTop="10dp" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:layout_marginLeft="20dp" 
       android:text="Age" 
       android:id="@+id/editAge" 
       android:textAppearance="?android:attr/textAppearanceMedium"/> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="DOB" 
       android:id="@+id/dobHead" 
       android:layout_marginTop="10dp" 
       android:layout_marginRight="20dp" 
       android:layout_marginLeft="20dp"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:layout_marginLeft="20dp" 
       android:text="DOB" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:id="@+id/editDob"/> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Height" 
       android:id="@+id/heightHead" 
       android:layout_marginTop="10dp" 
       android:layout_marginRight="20dp" 
       android:layout_marginLeft="20dp"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Height" 
       android:id="@+id/editHeight"/> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Weight" 
       android:id="@+id/weightHead" 
       android:layout_marginTop="10dp" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Weight" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:id="@+id/editWeight" 
       android:layout_marginTop="10dp" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Notes" 
       android:id="@+id/notesHead" 
       android:layout_marginLeft="20dp"/> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Template >" 
       android:layout_marginLeft="20dp" 
       android:id="@+id/notesBtn"/> 

     </LinearLayout> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:id="@+id/editNotes" 
      android:layout_marginLeft="20dp" 
      android:text="The notes go here" 
      android:layout_marginRight="20dp"/> 

    </LinearLayout> 
</ScrollView> 
+0

Я очень ценю ваши усилия, но вопрос решен. Предоставление вам +1 –

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