2016-11-10 3 views
0
<?xml version="1.0" encoding="utf-8"?> 
<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"> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/layout_blue_border" 
android:weightSum="1"> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="5" 
    android:layout_weight="1.5" 
    android:layout_margin="@dimen/abc_button_inset_horizontal_material" 
    android:outlineProvider="none"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:id="@+id/textView2" 
     android:layout_marginLeft="@dimen/abc_control_inset_material"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Moisture Probe Info" 
      android:id="@+id/textView9" 
      android:layout_weight="1" 
      android:layout_marginTop="@dimen/activity_horizontal_margin" 
      android:textSize="@dimen/abc_text_size_button_material" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:outlineProvider="none" 
     android:orientation="horizontal" 
     android:layout_below="@+id/ActvCal" 
     android:layout_alignLeft="@+id/display_tv" 
     android:layout_alignStart="@+id/display_tv" 
     android:weightSum="5" 
     android:layout_weight="0" > 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:weightSum="2" 
      android:layout_weight="1" 
      android:layout_margin="@dimen/activity_horizontal_margin" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Serial #:" 
       android:id="@+id/Serial" 
       android:layout_weight="1" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/serial_val" 
       android:layout_column="8" 
       android:layout_weight="1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:weightSum="2" 
      android:layout_margin="@dimen/activity_horizontal_margin" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Battery:" 
       android:id="@+id/Battery" 
       android:layout_weight="1" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/Battery_val" 
       android:layout_column="8" 
       android:text="0" 
       android:layout_alignParentEnd="true" 
       android:layout_weight="1" 
       android:layout_alignParentRight="true" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:weightSum="2" 
      android:layout_margin="@dimen/activity_horizontal_margin" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Firmware Ver:" 
       android:id="@+id/Firmware" 
       android:layout_weight="1" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/Firmware_val" 
       android:layout_column="8" 
       android:layout_weight="1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:weightSum="2" 
      android:layout_margin="@dimen/activity_horizontal_margin" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Date:" 
       android:id="@+id/date" 
       android:textIsSelectable="false" 
       android:layout_weight="1" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/date_val" 
       android:layout_column="8" 
       android:layout_alignParentEnd="true" 
       android:layout_weight="1" 
       android:layout_alignParentRight="true" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:weightSum="2" 
      android:layout_margin="@dimen/activity_horizontal_margin" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="MAC Addr:" 
       android:id="@+id/MACaddr" 
       android:layout_weight="1" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/mac_val" 
       android:layout_column="8" 
       android:layout_weight="1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="@dimen/activity_horizontal_margin" 
      android:layout_marginTop="@dimen/activity_horizontal_margin" 
      android:layout_marginRight="@dimen/activity_horizontal_margin"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Latitude" 
       android:id="@+id/Long_text" 
       android:layout_weight="1" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/Latitude_val" 
       android:layout_column="8" 
       android:layout_weight="1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="@dimen/activity_horizontal_margin" 
      android:layout_marginRight="@dimen/activity_horizontal_margin" 

android:layout_marginBottom="@dimen/activity_horizontal_margin"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Longitude" 
       android:id="@+id/textView3" 
       android:layout_weight="1" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/Longitude_val" 
       android:layout_column="8" 
       android:layout_weight="1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="@dimen/activity_horizontal_margin" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/Note" 
       android:layout_column="8" 
       android:layout_weight="1" /> 
     </LinearLayout> 
    </TableLayout> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="3" 
     android:layout_gravity="bottom" 

     android:gravity="bottom|fill_vertical" 
     android:layout_weight=".5" 
     android:layout_marginLeft="@dimen/activity_horizontal_margin"> 



     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button2" 
      android:layout_alignParentBottom="true" 
      android:layout_toLeftOf="@+id/Return2" 
      android:layout_toStartOf="@+id/Return2" 
      android:layout_alignTop="@+id/button1" 

      android:layout_weight="1" 
      android:layout_gravity="center_vertical" 

      android:layout_marginRight="@dimen/activity_horizontal_margin" 
      android:outlineProvider="none" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="" 
      android:id="@+id/button1" 
      android:layout_alignParentEnd="false" 
      android:layout_alignParentRight="false" 

      android:layout_weight="1" 

      android:layout_marginRight="@dimen/activity_horizontal_margin" 
      android:outlineProvider="none" /> 

     <Button 
      android:id="@+id/Return2" 
      android:text="Return to Main Menu" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:layout_alignTop="@+id/button2" 
      android:background="@drawable/button_shape_grey" 
      android:layout_weight="1" 

      android:textSize="@dimen/abc_text_size_caption_material" 
      android:layout_marginRight="@dimen/activity_horizontal_margin"   
/> 
    </LinearLayout> 
</LinearLayout> 

</LinearLayout> 

<ProgressBar 
    android:id="@+id/progressBar1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:indeterminate="false" 
    android:layout_weight=".1" 
    android:layout_marginTop="@dimen/activity_horizontal_margin" 
    android:layout_gravity="top|center_horizontal" /> 
</RelativeLayout> 

Ich bin neu in Android-Programmierung. Das Layout wird bei einigen Geräten korrekt angezeigt und bei anderen Geräten abgeschnitten. Ich habe Ränder wie "@ dimen/activity_horizontal_margin" im XML für das Layout hinzugefügt. Ich habe erwartet, dass diese nach der Bildschirmgröße berechnet werden, aber das ist nicht der Fall. Wie kann ich die Marge angeben, die nach dem verfügbaren Platz berechnet wird?Android-Layout schief für verschiedene Bildschirmgrößen

+0

Wenn Sie sich Ihren XML-Code für die ersten 2 'LinearLayouts' anschauen, setzen Sie im Eltern' LinearLayout' eine 'weightSum =" 1 "', aber im Kind 'LinearLayout' haben Sie' android: layout_weight = " 1.5 "' .. das ist mehr als 1. Auch wenn Sie gewichtete Layouts mit 'LinearLayout' verwenden, stellen Sie sicher, dass Sie die Höhe (für vertikale' LinearLayout') und Breite (für horizontale 'LinearLayout') auf' 0dp' setzen. In all deinen Layouts muss etwas aufgeräumt werden, da die Gewichte die schiebenden Layouts nicht aus der sichtbaren Ansicht herausrechnen. –

Antwort

0

Zuerst ist es nicht gut, dass Sie so viele ineinander eingepackte Layouts haben. Und zweitens, ist sehr schlecht, Gewicht in diesen Fällen zu verwenden, da Android viel Zeit braucht, um den Wert in der tiefsten Komponente zu zählen.

Auf diese Weise müssen Sie besser TableLayout für die gleichen Zwecke verwenden.

Verwandte Themen