2017-02-15 6 views
0

У меня есть свои взгляды в виде прокрутки, так что если содержимое больше размера экрана, пользователь может прокручивать вниз. Я заметил странную вещь.Android. ScrollView не выполняет прокрутку в первый раз, но затем, когда содержимое изменилось, это

В первый раз, когда контент появляется, он не прокручивается. Однако, когда пользователь меняет настройку, а содержимое просмотров, находящихся внутри перепрограммирования прокрутки, становится прокручиваемым.

Почему это? Понятно, что я имею в виду?

EDIT: Это происходит только на моем Nexus 5X. Но когда я использовал Samsung J10, он работает сразу.

Мой XML - это относительный макет с дочерним элементом прокрутки, который содержит другие виды.

Вот мой XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/content_home" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.apps.reuven.egertandcohentravel.Activities.HomeActivity" 
tools:showIn="@layout/activity_home"> 

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

    > 




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


     <ProgressBar 
      android:layout_width="50dp" 
      android:id="@+id/progressBar" 
      android:layout_height="50dp" 
      android:layout_centerInParent="true" 
      android:visibility="gone" 
      /> 

     <TextView 
      android:id="@+id/textViewLinkToOrder" 
      android:layout_marginTop="20dp" 
      android:layout_marginBottom="20dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Click here to book travel insurance." 
      android:textColor="@color/colorPrimary" 
      android:layout_centerHorizontal="true" 
      android:textSize="24sp" 
      android:gravity="center" 

      /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/buttons_linear_layout" 
      android:orientation="horizontal" 
      android:layout_below="@id/textViewLinkToOrder"> 

      <Button 
       android:layout_width="200dp" 
       android:id="@+id/choose_country_button" 
       android:onClick="onChooseCountryButtonClick" 
       android:layout_height="wrap_content" 
       android:text="Choose country" 
       android:layout_marginLeft="5dp" 
       android:background="@color/colorPrimary" 
       android:layout_weight="1" 
       android:textColor="#ffff" 
       android:layout_marginRight="5dp" 
       android:layout_below="@id/textViewLinkToOrder" 
       android:layout_centerHorizontal="true"/> 


      <Button 
       android:layout_width="200dp" 
       android:layout_weight="1" 
       android:background="@color/colorPrimary" 
       android:textColor="#fff" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:id="@+id/automatic_country_button" 
       android:layout_height="wrap_content" 
       android:text="My Location" 
       android:layout_below="@id/choose_country_button" 
       android:layout_centerHorizontal="true"/> 




     </LinearLayout> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 

      android:orientation="vertical" 
      android:id="@+id/linearLayoutAllDetails" 
      android:layout_below="@id/buttons_linear_layout" 
      > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="No country yet selected" 
       android:gravity="center" 
       android:id="@+id/textView_coumtry_name" 
       android:textColor="#000000" 
       android:textSize="30sp" 
       android:padding="5dp" 
       android:textStyle="bold" 
       android:layout_weight="1" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="horizontal" 
       android:paddingTop="20dp" 
       android:paddingBottom="20dp" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp" 
       > 

       <ImageView 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:src="@drawable/police"/> 

       <TextView 
        android:textSize="17sp" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Police" 
        android:textColor="#000000" 
        android:layout_gravity="center_vertical" /> 

       <TextView 
        android:layout_marginLeft="10dp" 
        android:textSize="17sp" 
        android:layout_marginRight="10dp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/police_text_view" 
        android:text="" 
        android:textColor="#000000" 
        android:layout_gravity="center_vertical"/> 

       <View 
        android:layout_width="0dp" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        /> 

       <ImageView 
        android:id="@+id/police_phone_button" 
        android:layout_width="30dp" 
        android:layout_gravity="center_vertical" 
        android:layout_height="30dp" 
        android:src="@android:drawable/sym_action_call" 


        /> 




      </LinearLayout> 



      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:paddingTop="20dp" 
       android:paddingBottom="20dp" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp"> 

       <ImageView 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:src="@drawable/ambulance"/> 

       <TextView 
        android:textSize="17sp" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Ambulance" 
        android:textColor="#000000" 
        android:layout_gravity="center_vertical" /> 

       <TextView 
        android:layout_marginLeft="10dp" 
        android:textSize="17sp" 
        android:layout_marginRight="10dp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/ambulance_text_view" 
        android:text="" 
        android:textColor="#000000" 
        android:layout_gravity="center_vertical"/> 

       <View 
        android:layout_width="0dp" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        /> 

       <ImageView 
        android:layout_width="30dp" 
        android:layout_gravity="center_vertical" 
        android:layout_height="30dp" 
        android:src="@android:drawable/sym_action_call" 
        android:id="@+id/ambulance_phone_button" 


        /> 




      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:paddingTop="20dp" 
       android:paddingBottom="20dp" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp"> 

       <ImageView 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:src="@drawable/israel_consulate"/> 

       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 

        <TextView 
         android:textSize="17sp" 
         android:layout_marginLeft="10dp" 
         android:layout_marginRight="10dp" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Israel Consulate" 
         android:textColor="#000000" 
         android:layout_gravity="center_vertical" /> 

        <TextView 
         android:layout_marginLeft="10dp" 
         android:textSize="17sp" 
         android:layout_marginRight="10dp" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/israel_consulate_text_view" 
         android:text="" 
         android:textColor="#000000" 
         android:layout_gravity="center_vertical"/> 



       </LinearLayout> 



       <View 
        android:layout_width="0dp" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        /> 

       <ImageView 
        android:layout_width="30dp" 
        android:layout_gravity="center_vertical" 
        android:layout_height="30dp" 
        android:src="@android:drawable/sym_action_call" 
        android:id="@+id/israel_phone_button" 

        /> 




      </LinearLayout> 




      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:paddingTop="20dp" 
       android:paddingBottom="20dp" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp"> 

       <ImageView 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:src="@drawable/chabad"/> 



       <LinearLayout 
        android:layout_width="250dp" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 

        <TextView 
         android:textSize="17sp" 
         android:layout_marginLeft="10dp" 
         android:layout_marginRight="10dp" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Beit Chabad" 
         android:textColor="#000000" 
         android:layout_gravity="center_vertical" /> 

        <TextView 
         android:layout_marginLeft="10dp" 
         android:textSize="17sp" 
         android:layout_marginRight="10dp" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/chabad_address_text_view" 
         android:text="3 Blue Street, USA" 
         android:textColor="#000000" 
         android:layout_gravity="center_vertical"/> 


        <TextView 
         android:layout_marginLeft="10dp" 
         android:textSize="17sp" 
         android:layout_marginRight="10dp" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/chabad_number_text_view" 
         android:text="+44 456 3245234" 
         android:textColor="#000000" 
         android:layout_gravity="center_vertical"/> 



       </LinearLayout> 


       <View 
        android:layout_width="0dp" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        /> 

       <ImageView 
        android:layout_width="30dp" 
        android:layout_gravity="center_vertical" 
        android:layout_height="30dp" 
        android:src="@android:drawable/sym_action_call" 
        android:id="@+id/chabad_phone_button" 


        /> 




      </LinearLayout> 





     </LinearLayout> 







    </RelativeLayout> 

</ScrollView> 

Большое спасибо, я не могу понять это.

+0

Я подозреваю, что имеется много давления памяти/процессора. Много расчет веса и вложенные слои представления. Вы можете использовать systrace для профиля. – Emma

ответ

0

У меня также была такая же проблема, и, добавив TableLayout внутри ScrollView, я решил проблему для меня. Затем добавьте свой контент (RelativeLayout) внутри TableLayout.

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:stretchColumns="1"> 

     <-- Your RelativeLayout goes here --> 

    </TableLayout> 
</ScrollView> 

Сообщите мне, если это решит проблему. Не забудьте добавить атрибут fillViewport = true в ScrollView, чтобы TableLayout соответствовал ширине и высоте представления родителя.

+0

Это ничего не изменило. Не работает. Но спасибо – RJB

+0

@ Μιχάλης Θεο для вас это сработало, потому что у вас есть 'android: fillViewport =" true "' – Ankit