4

Ich brauche eine Bildlaufansicht innerhalb eines relativen Layouts.ScrollView in einem RelativeLayout

Als ich die Scrollview hinzugefügt war dies das Ergebnis http://postimg.org/image/6abxth299/, wo die Komponenten sind, werden nur die Hälfte des Bildschirms einnimmt und wenn dieser Bildschirm geöffnet wird, die Tastatur kommt standardmäßig

<?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="fill_parent" 
    android:scrollbars="vertical" > 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context=".MainActivity" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/data_entry_layout"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Post Title" 
       android:id="@+id/post_title" 
       android:layout_alignBaseline="@+id/post_title_input" 
       android:layout_alignBottom="@+id/post_title_input" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:textSize="26px"/> 

      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/post_title_input" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       android:layout_toRightOf="@+id/post_title" 
       android:layout_toEndOf="@+id/post_title" 
       android:inputType="textCapSentences"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Post Description" 
       android:id="@+id/post_description" 
       android:layout_below="@+id/post_title_input" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginTop="39dp" 
       android:textSize="26px"/> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textMultiLine|textCapSentences" 
       android:ems="10" 
       android:id="@+id/editText" 
       android:layout_marginTop="16dp" 
       android:layout_below="@+id/post_description" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true"/> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/imageButton1" 
       android:layout_below="@+id/editText" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:baselineAlignBottom="false" 
       android:contextClickable="true" 
       android:src="@drawable/image_button_icon" 
       android:onClick="galleryIntent"/> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Cancel" 
       android:id="@+id/cancel" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_below="@id/imageButton1" 

       /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Submit" 
       android:id="@+id/submit" 
       android:layout_alignTop="@+id/cancel" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       android:layout_below="@id/imageButton1"/> 

    </RelativeLayout> 
</ScrollView> 
+0

nie zu RelativeLayout verwenden 'match_parent' wie Höhe, wenn innerhalb eines Scroll kommen zu entfernen, ändere es in 'wrap_content'. –

+0

hat es jedoch geändert, Komponenten nehmen immer noch die Hälfte des Bildschirms – cgeekmt

+0

was willst du? –

Antwort

0

Versuchen unten mit denen Sie Ihre AndroidManifest in Ihrer diese Aktivität Tastatur zu entfernen, kommen standardmäßig bis

android:windowSoftInputMode="stateAlwaysHidden|adjustResize" 

und Verwenden android:layout_height="wrap_content" für Scrollview, sugesting verwendet Linearlayout mit vertikalen Ausrichtung Layouts für diesen Art der Verwendung.

+0

hast du es versucht? @cgeekmt –

+0

Ja, das funktionierte für die Tastatur. Vielen Dank! – cgeekmt

1

Die Höhe des ersten dirsct Kind von scrollview, sei es relativ oder linear Layout sollte Wrap Inhalt sein und nicht übereinstimmen Eltern. Auch die inneren Kinder sollten ein bestimmtes Gewicht oder eine bestimmte Größe haben und nicht wie bei imageButton mit Eltern übereinstimmen.

+0

änderte die Höhe auf 430px und es funktionierte. Ich glaube jedoch, dass es für andere Geräte nicht reaktionsfähig wäre oder? (d. h. die Höhe würde sich nicht entsprechend anpassen)? – cgeekmt

+0

Welche Höhe hast du auf 430px geändert? –

+0

der imagebutton cgeekmt

0

Ich denke, ScrollView funktioniert nicht in Relative Layout. Es ist besser, LinearLayout zu verwenden.

0

Versuchen Sie dieses ...

<?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" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:id="@+id/data_entry_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerHorizontal="true" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin"> 
     <RelativeLayout 
      android:id="@+id/Rel12345" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/post_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/post_title_input" 
      android:layout_alignBottom="@+id/post_title_input" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:text="Post Title" 
      android:textSize="26px" /> 

     <EditText 
      android:id="@+id/post_title_input" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_toEndOf="@+id/post_title" 
      android:layout_toRightOf="@+id/post_title" 
      android:inputType="textCapSentences" /> 

     <TextView 
      android:id="@+id/post_description" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/post_title_input" 
      android:layout_marginTop="39dp" 
      android:text="Post Description" 
      android:textSize="26px" /> 

     <EditText 
      android:id="@+id/editText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/post_description" 
      android:layout_marginTop="16dp" 
      android:ems="10" 
      android:inputType="textMultiLine|textCapSentences" /> 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/editText" 
      android:baselineAlignBottom="false" 
      android:contextClickable="true" 
      android:onClick="galleryIntent" 
      /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/Rel1234" 
      android:layout_below="@id/Rel12345" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true"> 

      <Button 
       android:id="@+id/cancel" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:text="Cancel"/> 

      <Button 
       android:id="@+id/submit" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignTop="@+id/cancel" 
       android:text="Submit" /> 
     </RelativeLayout> 
    </RelativeLayout> 
</ScrollView> 

und Versuchen unten an deine AndroidManifes Hinzufügen Tastatur standardmäßig

android:windowSoftInputMode="stateAlwaysHidden|adjustResize" 
+0

@cgeekmt Dies ist die getestete Komplettlösung Ihres Problems –