2016-05-27 6 views
2

Ich muss das Layout auf die Art und Weise, dass keine hart codierten Werte in dp, so dass ich versuche Gewicht zu verwenden, um Höhe zu Ansichten.I versuchen UI hat die gleiche aussehen sowohl Handys als auch Tablets.Höhe geben, scrollview ohne Größe in dp

Aber die Bildlaufansicht lässt keine layout_weight zu Ich habe Höhe der Scrollview festgelegt. Ich möchte das nicht tun.

Wie kann ich die Höhe des Scrollview oder dem Haupt eingeschlossen Container Layout in das Gewicht mit/ohne harte Kodierung in dp?

XML

<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:orientation="vertical"> 


    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="120dp"//WANT TO AVOID HARD CODING 
     android:layout_above="@+id/btn_signup" 
     android:fadeScrollbars="false" 
     android:scrollbarAlwaysDrawVerticalTrack="true" 
     > 

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

      android:orientation="vertical" 
      android:paddingLeft="20dp" 
      android:paddingRight="20dp" 
      > 

      <android.support.design.widget.TextInputLayout 
       android:id="@+id/input_layout_name" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <EditText 
        android:id="@+id/roomno_et" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="ROOM NO" 
        android:inputType="number" 
        android:singleLine="true"/> 
      </android.support.design.widget.TextInputLayout> 


      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="FIRST NAME" 
        android:inputType="text" 
        android:singleLine="true"/> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="LAST NAME" 
        android:inputType="text" 
        android:singleLine="true"/> 
      </android.support.design.widget.TextInputLayout> 
     </LinearLayout> 

    </ScrollView> 

    <Button 
     android:id="@+id/btn_signup" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="20dp" 
     android:background="@color/colorPrimary" 
     android:text="Checkin" 
     android:textColor="@android:color/white"/> 


</RelativeLayout> 

enter image description here enter image description here

Antwort

0

können Sie die ScrollView in einem Elternteil setzen LinearLayout und Gewicht zuweisen.

Etwas wie folgt aus:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight = "1"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/btn_signup" 
    android:fadeScrollbars="false" 
    android:scrollbarAlwaysDrawVerticalTrack="true"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp"> 

     <android.support.design.widget.TextInputLayout 
      android:id="@+id/input_layout_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <EditText 
       android:id="@+id/roomno_et" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="ROOM NO" 
       android:inputType="number" 
       android:singleLine="true"/> 
     </android.support.design.widget.TextInputLayout> 


     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="FIRST NAME" 
       android:inputType="text" 
       android:singleLine="true"/> 
     </android.support.design.widget.TextInputLayout> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="LAST NAME" 
       android:inputType="text" 
       android:singleLine="true"/> 
     </android.support.design.widget.TextInputLayout> 
    </LinearLayout> 
</ScrollView> 
</LinearLayout> 

<Button 
    android:id="@+id/btn_signup" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_marginTop="20dp" 
    android:background="@color/colorPrimary" 
    android:text="Checkin" 
    android:textColor="@android:color/white"/> 
+0

Aber Ihr Code noch hat android: layout_height = "120dp" für Scroll –

+0

ops ich sie zu aktualisieren vergessen, – Max