2015-11-12 2 views
0

Я пытаюсь сделать ряд для recyclerview, строка будет расщепляется в 3 колонкиандроида относительная компоновка не работает должным образом

  1. Первый - Кнопка Image
  2. второго контента (TextViews)
  3. Третий - Кнопка Image

и когда я загрузить огромное содержание, он делает макет расти, и его хорошо, но я хочу, боковые панели, чтобы расти в высоту тоже:

, что я хочу (и Android-студия SHOW, которая будет (лжец =()):

enter image description here

и то, что я действительно получил:

enter image description here

и мой row.xml является это:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <RelativeLayout 
     android:id="@+id/thebig_father_layout" 
     android:layout_width="match_parent" 
     android:background="@android:color/holo_blue_bright" 
     android:layout_height="match_parent"> 


     <RelativeLayout 
      android:background="@android:color/holo_red_dark" 
      android:layout_alignParentLeft="true" 
      android:gravity="center_vertical" 
      android:id="@+id/i_must_grow_in_height" 
      android:layout_width="48dp" 
      android:layout_height="match_parent"> 
      <TextView 
       android:text="Grow and to center!!!!" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </RelativeLayout> 



     <RelativeLayout 

      android:background="@android:color/holo_green_dark" 
      android:layout_toRightOf="@+id/i_must_grow_in_height" 

      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_toLeftOf="@+id/relativeLayout4"> 

      <LinearLayout 
       android:gravity="center_vertical" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <TextView 
        android:text="Im the content i can grow in height but the side panels must GROW TOO" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

       <TextView 
        android:text="Im the content i can grow in height but the side panels must GROW TOO" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

       <TextView 
        android:text="Im the content i can grow in height but the side panels must GROW TOO" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

       <TextView 
        android:text="Im the content i can grow in height but the side panels must GROW TOO" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

       <Button 
        android:text="Random Content" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
       <Button 
        android:text="Random Content" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
       <Button 
        android:text="Random Content" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
       <Button 
        android:text="Random Content" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
       <Button 
        android:text="Random Content" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
       <Button 
        android:text="Random Content" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 


      </LinearLayout> 
     </RelativeLayout> 



     <RelativeLayout 
      android:background="@android:color/holo_red_dark" 
      android:layout_width="48dp" 
      android:gravity="center_vertical" 

      android:layout_alignParentRight="true" 
      android:layout_height="match_parent" 
      android:id="@+id/relativeLayout4"> 

      <TextView 
       android:text="C'mon i need it too" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </RelativeLayout> 

    </RelativeLayout> 
</RelativeLayout> 

кто-то может объяснить ПОЧЕМУ его не растут (красный макет)?

+0

Не могли бы вы показать нам как вы показываете этот макет? просто с setcontentview? –

+0

Добавить центр в вертикальном положении верен в компоновке релейного выхода. Я надеюсь на его работу. – Destro

+0

@NikoYuwono yep, ничего особенного просто -> '' 'View v = LayoutInflater.from (parent.getContext()) .inflate (R.layout.mynew_textview, parent, false);' '' – user2582318

ответ

2

В этих макетах, где вы использовали

android:background="@android:color/holo_red_dark"

сделать их высота автоматически в зависимости от содержания не до высоты контейнера.

android:layout_height="wrap_content" 

и если вы хотите изображения-кнопки для перехода красный с начала попробуйте высоту TextView внутри этого красного цвета RelativeLayout как match_parent.

<RelativeLayout 
     android:id="@+id/relativeLayout4" 
     android:layout_width="48dp" 
     android:layout_height="match_parent" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:background="@color/Red" 
     android:gravity="center" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:gravity="center" 
      android:layout_height="match_parent" 
      android:text="C&apos;mon i need it too" /> 
</RelativeLayout> 

Снимок экрана моего LG OG (4.1.2).

enter image description here Вот полный Xml, очень минутные изменения, я думаю, вы должны очистить проект и попробовать на другом устройстве или эмуляторе ...

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<RelativeLayout 
    android:id="@+id/thebig_father_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/Blue" > 

    <RelativeLayout 
     android:id="@+id/i_must_grow_in_height" 
     android:layout_width="48dp" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:background="@color/Red" 
     android:gravity="center_vertical" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Grow and to center!!!!" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toEndOf="@+id/i_must_grow_in_height" 
     android:layout_toLeftOf="@+id/relativeLayout4" 
     android:layout_toRightOf="@+id/i_must_grow_in_height" 
     android:layout_toStartOf="@+id/relativeLayout4" 
     android:background="@color/Blue" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_vertical" 
      android:orientation="vertical" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Im the content i can grow in height but the side panels must GROW TOO" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Im the content i can grow in height but the side panels must GROW TOO" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Im the content i can grow in height but the side panels must GROW TOO" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Im the content i can grow in height but the side panels must GROW TOO" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Random Content" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Random Content" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Random Content" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Random Content" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Random Content" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Random Content" /> 
     </LinearLayout> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relativeLayout4" 
     android:layout_width="48dp" 
     android:layout_height="match_parent" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:background="@color/Red" 
     android:gravity="center" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:gravity="center" 
      android:layout_height="match_parent" 
      android:text="C&apos;mon i need it too" /> 
    </RelativeLayout> 
</RelativeLayout> 

+0

не работает, вы можете вставить вас в полный .xml? – user2582318

1

row.xml код вам выложили для меня работу? проверьте, есть ли у вас несколько файлов row.xml в вашем проекте с разной плотностью и т. д. (включены модули/библиотеки). Один из способов проверить это легко - навести указатель мыши над кодом R.layout.row в свой код Java и нажать удерживая Ctrl. Это даст все места, где находится этот файл row.xml.

View v = LayoutInflater.from (parent.getContext()) .inflate (R.layout.строка, родительская, ложная);

Я предложил бы использовать менее вложенными точки зрения, и это может быть сделано с LinearLayout, а также:

RelativeLayout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/holo_blue_bright"> 

<ImageButton 
    android:id="@+id/imageButtonOnLeft" 
    android:layout_width="48dp" 
    android:layout_height="match_parent" 

    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 

    android:layout_gravity="center_vertical" 
    android:background="@android:color/holo_red_dark" 
    android:contentDescription="info button" 
    android:src="@android:drawable/ic_dialog_info" 
    android:text="Grow and to center!!!!" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_vertical" 

    android:layout_toEndOf="@+id/imageButtonOnLeft" 
    android:layout_toRightOf="@+id/imageButtonOnLeft" 

    android:layout_toLeftOf="@+id/imageButtonOnRight" 
    android:layout_toStartOf="@+id/imageButtonOnRight" 

    android:background="@android:color/holo_green_dark" 
    android:gravity="center_vertical" 
    android:orientation="vertical" 
    android:padding="8dp"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Im the content i can grow in height but the side panels must GROW TOO" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Random Content" /> 

</LinearLayout> 

<ImageButton 
    android:id="@+id/imageButtonOnRight" 
    android:layout_width="48dp" 
    android:layout_height="match_parent" 

    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 

    android:layout_gravity="center_vertical" 
    android:background="@android:color/holo_red_dark" 
    android:contentDescription="dialer button" 
    android:src="@android:drawable/ic_dialog_dialer" 
    android:text="C'mon i need it too" /> 

</RelativeLayout> 

LinearLayout

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/holo_blue_bright" 
android:orientation="horizontal"> 


<ImageButton 
    android:id="@+id/imageButtonOnLeft" 
    android:layout_width="48dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_vertical" 
    android:background="@android:color/holo_red_dark" 
    android:contentDescription="info button" 
    android:src="@android:drawable/ic_dialog_info" 
    android:text="Grow and to center!!!!" /> 


<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_vertical" 
    android:layout_weight="1" 
    android:background="@android:color/holo_green_dark" 
    android:gravity="center_vertical" 
    android:orientation="vertical" 
    android:padding="8dp"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Im the content i can grow in height but the side panels must GROW TOO" /> 


    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Random Content" /> 


</LinearLayout> 


<ImageButton 
    android:id="@+id/imageButtonOnRight" 
    android:layout_width="48dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_vertical" 
    android:background="@android:color/holo_red_dark" 
    android:contentDescription="dialer button" 
    android:src="@android:drawable/ic_dialog_dialer" 
    android:text="C'mon i need it too" /> 


</LinearLayout> 
+0

Огромное спасибо, может быть, проблема состояла в много вложенных панелей, можете ли вы объяснить, почему в LinearLayout '' 'android: layout_width =" 0dp "и weight = 1? '' ' – user2582318

+0

Quoted Lint Warning:« Когда только один виджет в LinearLayout определяет вес, более эффективно назначать ему ширину/высоту 0dp, так как он все равно поглотит все оставшееся пространство. С объявленной шириной/высота 0dp, он не должен сначала измерять свой размер ». посмотрите этот ответ, чтобы узнать больше о весе: http://stackoverflow.com/questions/3995825/what-does-androidlayout-weight-mean – TouchBoarder

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