2017-08-08 1 views
0

Hallo, ich versuche Scrollview zu meinem Layout hinzuzufügen, aber es gibt mir Fehler scrollview kann nur ein direktes Kind Host. Ich möchte nur edittext blättern, nicht ein imageviev und button button beide müssen Konstanten sein. Und wenn ich mein Gerät auf Landschaft rotiere, sind das keine Displays. bitte die Lösung für diesesScrollview gibt Fehler in Android

Hier geben ist mein Code

<?xml version="1.0" encoding="utf-8"?> 
<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="match_parent" 
    android:background="#aeabab" 
    android:orientation="vertical" 
    android:weightSum="1"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbarforprofile" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#fff" 
     android:minHeight="?attr/actionBarSize" 
     android:titleTextColor="#000" 
     app:theme="@style/ToolbarColoredBackArrow" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="10dp" 
     android:background="@mipmap/icon_car" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:gravity="center" 
     android:text="CAR PREFERENCE" 
     android:textColor="#111" 
     android:textSize="17dp" /> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="20dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:layout_marginTop="5dp" 
      android:background="#ffffff" 
      android:orientation="vertical"> 

     <EditText 
      android:id="@+id/editText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:drawableLeft="@mipmap/icon_location" 
      android:drawablePadding="10dp" 
      android:hint="WHERE TO GO" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:paddingLeft="5dp" 
      android:text="FROM DATE" 
      android:textColor="#111" 
      android:textSize="17dp" /> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:drawableLeft="@mipmap/icon_calendar" 
      android:drawablePadding="10dp" 
      android:hint="30/05/2017" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:paddingLeft="5dp" 
      android:text="TO DATE" 
      android:textColor="#111" 
      android:textSize="17dp" /> 

     <EditText 
      android:id="@+id/editText3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:drawableLeft="@mipmap/icon_calendar" 
      android:drawablePadding="5dp" 
      android:hint="30/05/2017" /> 

     <EditText 
      android:id="@+id/editText4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:drawableLeft="@mipmap/icon_clock" 
      android:drawablePadding="5dp" 
      android:hint="10 AM" /> 


     <EditText 
      android:id="@+id/editText5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:drawableLeft="@mipmap/icon_people" 
      android:drawablePadding="5dp" 
      android:hint="NUMBER OF PERSON" 
      android:inputType="number" 
      android:maxLines="1" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:paddingLeft="8dp" 
      android:text="CAR TYPE" 
      android:textColor="#111" 
      android:textSize="17dp" /> 

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

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

       <RadioButton 
        android:id="@+id/radioButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:text="SEDDAN" /> 

       <RadioButton 
        android:id="@+id/radioButton2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right" 
        android:text="HACHBACK" /> 

       <RadioButton 
        android:id="@+id/radioButton3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="SUV" /> 
      </RadioGroup> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginBottom="7dp" 
     android:layout_marginTop="-57dp" 
     android:gravity="center" 
     android:scaleX="0.9" 
     android:scaleY="0.9"> 

     <Button 
      android:id="@+id/btn_submit" 
      style="@style/Widget.AppCompat.Button.Colored" 
      android:layout_width="wrap_content" 
      android:layout_height="45dp" 
      android:layout_gravity="center" 
      android:background="@drawable/rounded_green" 
      android:ems="10" 
      android:gravity="center" 
      android:text="ORDER NOW" 
      android:textSize="20dp" 
      android:textStyle="bold" /> 


    </RelativeLayout> 
</LinearLayout> 


    </LinearLayout> 
+0

Wenn Sie nur den EditText scrollen möchten, legen Sie seine Höhe auf wrap_content und es wird automatisch scrollen und entfernen Sie die Bildlaufansicht –

Antwort

0

Sie können einen direkten Kind ScrollView platzieren, die den aktuellen neuesten API gilt zumindest ist. Sie haben LinearLayout und mehrere EditText s als direktes Kind von ScrollView, was zum Absturz führt.

Sie können mehrere View s in ViewGroup wickeln die RelativeLayout sein kann, LinearLayout oder ein FrameLayout aber stellen Sie sicher ScrollView haben immer einen direkten Kind.

<android.support.v4.widget.NestedScrollView 
    ..... 
    ..... 

    <LinearLayout 

    <EditText 

    <EditText 

    <TextView 

    ..... 
    ..... 

</android.support.v4.widget.NestedScrollView> 

dieses Versuchen hat nur ein direktes Kind, wie die Fehlermeldung Staaten

<android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="20dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:layout_marginTop="5dp" 
      android:background="#ffffff" 
      android:orientation="vertical"> 

      <EditText 
       android:id="@+id/editText" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:drawableLeft="@mipmap/icon_location" 
       android:drawablePadding="10dp" 
       android:hint="WHERE TO GO" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:paddingLeft="5dp" 
       android:text="FROM DATE" 
       android:textColor="#111" 
       android:textSize="17dp" /> 

      <EditText 
       android:id="@+id/editText2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:drawableLeft="@mipmap/icon_calendar" 
       android:drawablePadding="10dp" 
       android:hint="30/05/2017" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:paddingLeft="5dp" 
       android:text="TO DATE" 
       android:textColor="#111" 
       android:textSize="17dp" /> 

      <EditText 
       android:id="@+id/editText3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:drawableLeft="@mipmap/icon_calendar" 
       android:drawablePadding="5dp" 
       android:hint="30/05/2017" /> 

      <EditText 
       android:id="@+id/editText4" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:drawableLeft="@mipmap/icon_clock" 
       android:drawablePadding="5dp" 
       android:hint="10 AM" /> 


      <EditText 
       android:id="@+id/editText5" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:drawableLeft="@mipmap/icon_people" 
       android:drawablePadding="5dp" 
       android:hint="NUMBER OF PERSON" 
       android:inputType="number" 
       android:maxLines="1" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:paddingLeft="8dp" 
       android:text="CAR TYPE" 
       android:textColor="#111" 
       android:textSize="17dp" /> 

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

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

        <RadioButton 
         android:id="@+id/radioButton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_horizontal" 
         android:text="SEDDAN" /> 

        <RadioButton 
         android:id="@+id/radioButton2" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="right" 
         android:text="HACHBACK" /> 

        <RadioButton 
         android:id="@+id/radioButton3" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="SUV" /> 
       </RadioGroup> 
      </LinearLayout> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 
+0

wo kann ich scrollview – Yogesh

+0

@Yogesh Überprüfen Sie meine aktualisierte Antwort – Rahul

0

Ihres NestedScrollView kann. Sie haben mehrere direkte Kinder, so dass es nicht funktioniert.

Um dies zu beheben, können Sie alle direkten untergeordneten Elemente der NestedScrollView in eine LinearLayout umhüllen. Dadurch erhält die Bildlaufansicht nur ein Kind: das neue LinearLayout.

LinearLayout ist nur eine ViewGroup können Sie verwenden, aber es ist wahrscheinlich die am besten geeignete in diesem Fall.