2014-01-03 4 views
2

У меня есть ImageView, который я установил в android:layout_alignParentRight="true", однако он не отображается в правой части экрана, и я не уверен, почему (это белый квадрат, горизонтально на скриншоте ниже).android: layout_alignParentRight = "true" ничего не делает

Я понимаю, что это можно использовать только с RelativeLayout, но я использовал один - так что я точно не знаю, почему это происходит.

<?xml version="1.0" encoding="utf-8"?> 
<com.example.project.DragLayer xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher" 
    android:id="@+id/drag_layer" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/black" > 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:weightSum="1.0" > 

      <GridView 
       android:id="@+id/image_grid_view" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:layout_weight="0.8" 
       android:background="@color/grid_background" 
       android:gravity="center" 
       android:horizontalSpacing="2dip" 
       android:numColumns="@integer/num_columns" 
       android:stretchMode="columnWidth" 
       android:verticalSpacing="2dip" /> 

      <RelativeLayout 
       android:id="@+id/bottom_part" 
       android:layout_width="fill_parent" 
       android:layout_height="200dp" 
       android:layout_centerHorizontal="true" 
       android:layout_weight="0.2" 
       android:background="@android:color/black" 
       android:orientation="horizontal" 
       android:weightSum="1.0" > 

       <Button 
        android:id="@+id/button_add_image" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:onClick="onClickAddImage" 
        android:text="Add image" /> 

       <com.example.project.DeleteZone 
        android:id="@+id/delete_zone_view" 
        android:layout_width="60dp" 
        android:layout_height="60dp" 
        android:src="@drawable/delete_zone" /> 

       <FrameLayout 
        android:id="@+id/image_source_frame" 
        android:layout_width="fill_parent" 
        android:layout_height="80dp" 
        android:layout_weight="0.5" > 

        <RelativeLayout 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:layout_alignParentRight="true" 
         android:layout_gravity="right" 
         android:layout_marginRight="5dp" 
         android:layout_weight="1" > 

         <ImageView 
          android:id="@+id/sqwhite" 
          android:layout_width="100dp" 
          android:layout_height="100dp" 
          android:layout_alignParentRight="true" 
          android:layout_gravity="right" 
          android:layout_marginRight="5dp" 
          android:layout_weight="1" /> 

         <EditText 
          android:id="@+id/editText1" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_alignParentRight="true" 
          android:layout_below="@id/sqwhite" 
          android:layout_marginRight="5dp" > 

          <requestFocus /> 
         </EditText> 

         <TextView 
          android:id="@+id/textView1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_alignParentRight="true" 
          android:layout_below="@id/editText1" 
          android:layout_marginRight="5dp" 
          android:text="" 
          android:textColor="@android:color/white" /> 
        </RelativeLayout> 
       </FrameLayout> 
      </RelativeLayout> 
     </LinearLayout> 
    </LinearLayout> 

</com.example.project.DragLayer> 

enter image description here

ответ

0

Один вопиющий вещь, которая выскакивает у меня есть переопределение Xmlns, что любой компилятор не любит и может помешать правильной генерации макета. Когда я удалил это и некоторые из ваших мертвых кодов и попытался запустить это, «sqwhite» появился с правой стороны. Смотрите, если крепления этих элементов помогает:

  • Ваш первый LinearLayout переопределяет XML пространство имен, которое является ошибкой. Это может быть то, что мешает XML правильно компилировать.

Другие мелкие предметы:

  • layout_weight относится только к детям LinearLayout с, так что наличие их в других ViewGroups ненужно. Снимите их с image_source_frame и ее детей
  • Имея bottom_partlayout_centerHorizontal в вертикальном LinearLayout является излишним, его также следует удалить.
  • Имея layout_alignParentRight в вашем RelativeLayout, бесполезно, так как только дети RelativeLayout s могут его использовать. Удалите.
  • Возможно, мне не хватает его из кода, который вы предоставили, но где же собственно белый квадрат? Вы не установили атрибут android:src на ImageView. Возможно ли, что фактический sqwhite находится в нужном месте, и что этот белый квадрат представляет что-то еще?

EDIT: Я переклеил ваш код здесь, с перечисленными мной элементами. Возможно, это поможет:

<?xml version="1.0" encoding="utf-8"?> 
<com.example.project.DragLayer xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drag_layer" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/black" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:weightSum="1.0" > 

      <GridView 
       android:id="@+id/image_grid_view" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:layout_weight="0.8" 
       android:background="@color/grid_background" 
       android:gravity="center" 
       android:horizontalSpacing="2dip" 
       android:numColumns="@integer/num_columns" 
       android:stretchMode="columnWidth" 
       android:verticalSpacing="2dip" /> 

      <RelativeLayout 
       android:id="@+id/bottom_part" 
       android:layout_width="fill_parent" 
       android:layout_height="200dp" 
       android:layout_weight="0.2" 
       android:background="@android:color/black" 
       android:weightSum="1.0" > 

       <Button 
        android:id="@+id/button_add_image" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:onClick="onClickAddImage" 
        android:text="Add image" /> 

       <com.example.project.DeleteZone 
        android:id="@+id/delete_zone_view" 
        android:layout_width="60dp" 
        android:layout_height="60dp" 
        android:src="@drawable/delete_zone" /> 

       <FrameLayout 
        android:id="@+id/image_source_frame" 
        android:layout_width="fill_parent" 
        android:layout_height="80dp" > 

        <RelativeLayout 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:layout_gravity="right" 
         android:layout_marginRight="5dp" > 

         <ImageView 
          android:id="@+id/sqwhite" 
          android:layout_width="100dp" 
          android:layout_height="100dp" 
          android:layout_alignParentRight="true" 
          android:layout_gravity="right" 
          android:layout_marginRight="5dp" 
          android:src="@android:drawable/ic_delete" /> <!-- for testing --> 

         <EditText 
          android:id="@+id/editText1" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_alignParentRight="true" 
          android:layout_below="@id/sqwhite" 
          android:layout_marginRight="5dp" /> 

         <TextView 
          android:id="@+id/textView1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_alignParentRight="true" 
          android:layout_below="@id/editText1" 
          android:layout_marginRight="5dp" 
          android:text="" 
          android:textColor="@android:color/white" /> 
        </RelativeLayout> 
       </FrameLayout> 
      </RelativeLayout> 
     </LinearLayout> 
    </LinearLayout> 
</com.example.project.DragLayer> 
Смежные вопросы