2015-11-03 3 views
0

У меня есть Layout.xml, который имеет видимый и невидимый/Gone компонент. Я хочу, когда Убираемый компонент «Видимость» становится видимым, а макет должен прокручиваться.Как иметь невидимый прокручиваемый макет

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

<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" 
    xmlns:materialdesign="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/root_view" 
    xmlns:roid="http://schemas.android.com/apk/res-auto" 
    tools:context=".MainActivity" 
    android:background="@color/backgroud_user"> 


    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="120dp" 
     android:src="@drawable/comp_icon" /> 



    <RelativeLayout 
     android:id="@+id/LoginBox" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="20dp" 
     android:layout_below="@+id/imageView1" 
     android:layout_centerInParent="true"> 

     <EditText 
      android:id="@+id/nameText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="text" 
      android:hint="Name" 
      android:theme="@style/MyEditTextTheme" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:padding="20dp" 
      android:textColorHint="#C5CAE9" 
      /> 


     <EditText 
      android:layout_below="@+id/nameText" 
      android:id="@+id/mobileText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="number" 
      android:hint="Mobile Number" 
      android:maxLength="10" 
      android:theme="@style/MyEditTextTheme" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:padding="20dp" 
      android:textColorHint="#C5CAE9" 
      /> 

     <EditText 
      android:layout_below="@+id/mobileText" 
      android:id="@+id/employerText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="text" 
      android:hint="Select Employer(s)" 
      android:focusable="false" 
      android:visibility="gone" 
      android:textColor="@color/white" 
      android:theme="@style/MyEditTextTheme" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:padding="20dp" 
      android:textColorHint="#C5CAE9" /> 

     <com.gc.materialdesign.NewMaterials.Spinner 
      android:layout_below="@+id/employerText" 
      android:id="@+id/employer_spinner_id" 
      style="@style/Material.Widget.Spinner.Light" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:rd_style="@style/Material.Drawable.Ripple.Wave.Light" 
      app:rd_enable="true" 
      app:rd_delayClick="false" 
      app:spn_labelEnable="true" 
      app:spn_label="Employer" 
      android:visibility="gone" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:paddingTop="20dp" 
      android:paddingBottom="20dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      app:spn_arrowSwitchMode="true" 
      app:spn_arrowAnimDuration="@android:integer/config_shortAnimTime" 
      app:spn_arrowInterpolator="@android:anim/decelerate_interpolator"/> 

     <LinearLayout 
      android:id="@+id/linearlayoutCheckbox" 
      android:layout_below="@+id/employer_spinner_id" 
      android:layout_width="match_parent" 
      android:visibility="gone" 
      android:layout_height="wrap_content"> 

     <com.gc.materialdesign.views.CheckBox 
      android:id="@+id/noEmployercheckboxid" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:paddingTop="20dp" 
      android:paddingBottom="20dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="10dp" 
      /> 

      <TextView 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:text="Employer Unknown"/> 
     </LinearLayout> 

     <com.gc.materialdesign.views.ButtonRectangle 
      android:id="@+id/loginButton" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:text="VALIDATE" 
      android:gravity="center|center_horizontal" 
      android:layout_below="@+id/linearlayoutCheckbox" 
      android:layout_marginTop="7sp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:textColor="#1A237E"/> 



    </RelativeLayout> 

</RelativeLayout> 

Пожалуйста, помогите мне достичь.

+0

использования 'ScrollView' в качестве родительского вида для второго по отношению расположения – Shvet

ответ

1

Добавить ScrollView над вашим RelativeLayout. Установите для него атрибуты позиции вашего Относительного макета (например, поля) и измените его высоту на WRAP_CONTENT.

<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" 
    xmlns:materialdesign="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/root_view" 
    xmlns:roid="http://schemas.android.com/apk/res-auto" 
    tools:context=".MainActivity" 
    android:background="@color/backgroud_user"> 


    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="120dp" 
     android:src="@drawable/comp_icon" /> 


    <ScrollView 
     android:id="@+id/scrollView" 
     android:width="match_parent" 
     android:height="match_parent" 
     android:layout_marginTop="20dp" 
     android:layout_centerInParent="true" 
     android:below="@+id/imageView1"> 

     <RelativeLayout 
      android:id="@+id/LoginBox" 
      android:layout_width="match_content" 
      android:layout_height="wrap_content"> 

      ... 
     </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 
+0

Thanx много. Это сработало для меня. –

1

Вы должны использовать ScrollView для прокрутки RelativeLayout, когда он находится в видимом режиме. На самом деле вы должны использовать VISIBLE и GONE свойства на ScrollView и сделать второй RelativeLayout ИТС childview

<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" 
    xmlns:materialdesign="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/root_view" 
    xmlns:roid="http://schemas.android.com/apk/res-auto" 
    tools:context=".MainActivity" 
    android:background="@color/backgroud_user"> 


    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="120dp" 
     android:src="@drawable/comp_icon" /> 

    <ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/linearLayout" 
    android:layout_centerInParent="true" 
    android:visibility="visible"> 

    <RelativeLayout 
     android:id="@+id/LoginBox" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="20dp" 
     android:layout_below="@+id/imageView1" 
     android:layout_centerInParent="true"> 

     <EditText 
      android:id="@+id/nameText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="text" 
      android:hint="Name" 
      android:theme="@style/MyEditTextTheme" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:padding="20dp" 
      android:textColorHint="#C5CAE9" 
      /> 


     <EditText 
      android:layout_below="@+id/nameText" 
      android:id="@+id/mobileText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="number" 
      android:hint="Mobile Number" 
      android:maxLength="10" 
      android:theme="@style/MyEditTextTheme" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:padding="20dp" 
      android:textColorHint="#C5CAE9" 
      /> 

     <EditText 
      android:layout_below="@+id/mobileText" 
      android:id="@+id/employerText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="text" 
      android:hint="Select Employer(s)" 
      android:focusable="false" 
      android:visibility="gone" 
      android:textColor="@color/white" 
      android:theme="@style/MyEditTextTheme" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:padding="20dp" 
      android:textColorHint="#C5CAE9" /> 

     <com.gc.materialdesign.NewMaterials.Spinner 
      android:layout_below="@+id/employerText" 
      android:id="@+id/employer_spinner_id" 
      style="@style/Material.Widget.Spinner.Light" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:rd_style="@style/Material.Drawable.Ripple.Wave.Light" 
      app:rd_enable="true" 
      app:rd_delayClick="false" 
      app:spn_labelEnable="true" 
      app:spn_label="Employer" 
      android:visibility="gone" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:paddingTop="20dp" 
      android:paddingBottom="20dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      app:spn_arrowSwitchMode="true" 
      app:spn_arrowAnimDuration="@android:integer/config_shortAnimTime" 
      app:spn_arrowInterpolator="@android:anim/decelerate_interpolator"/> 

     <LinearLayout 
      android:id="@+id/linearlayoutCheckbox" 
      android:layout_below="@+id/employer_spinner_id" 
      android:layout_width="match_parent" 
      android:visibility="gone" 
      android:layout_height="wrap_content"> 

     <com.gc.materialdesign.views.CheckBox 
      android:id="@+id/noEmployercheckboxid" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:paddingTop="20dp" 
      android:paddingBottom="20dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="10dp" 
      /> 

      <TextView 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:text="Employer Unknown"/> 
     </LinearLayout> 

     <com.gc.materialdesign.views.ButtonRectangle 
      android:id="@+id/loginButton" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:text="VALIDATE" 
      android:gravity="center|center_horizontal" 
      android:layout_below="@+id/linearlayoutCheckbox" 
      android:layout_marginTop="7sp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:textColor="#1A237E"/> 



    </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 
Смежные вопросы