2016-11-10 9 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> 

Я новичок в программировании на Android. Макет правильно отображается на некоторых устройствах и отключается другими. Я добавил поля, такие как «@ dimen/activity_horizontal_margin» в XML для макета. Я ожидал, что они будут рассчитаны в соответствии с размером экрана, но это не так. Как я могу указать маржу, которая рассчитывается в соответствии с доступным пространством?Android Layout перекошен для разных размеров экрана

+0

Если вы посмотрите на свой xml-код для первых 2 'LinearLayouts', вы устанавливаете в родительском' LinearLayout' 'weightSum =" 1 "', однако в дочернем 'LinearLayout' вы имеете' android: layout_weight = " 1.5 "' .., который больше 1. Кроме того, при использовании взвешенных макетов с 'LinearLayout' убедитесь, что у вас есть высота (для вертикального' LinearLayout') и ширина (для горизонтального 'LinearLayout'), установленная на' 0dp'. Во всех ваших макетах требуется некоторая очистка, потому что весы не набирают его толкающие макеты из видимого вида. –

ответ

0

Во-первых, это нехорошо, что у вас так много завернутых макетов один в другой. И, во-вторых, очень плохо использовать вес в этих случаях, так как Android нужно много времени, чтобы подсчитать значение внутри самого глубокого компонента.

Таким образом, вам необходимо использовать TableLayout для тех же целей.

 Смежные вопросы

  • Нет связанных вопросов^_^