2016-11-10 2 views
0

У меня проблема с LinearLayout, которая находится ниже списка. Я попытался указать вес и макет списка и выше, установите layout_height в 0dp, но ничего не было.Линейная компоновка под списком ListView, некоторые части не видны?

Вот мой XML-код:

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

    <LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="100" 
     android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" 
      /> 
     </LinearLayout> 

      <ListView 
       android:id="@+id/lvMain" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
      </ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:gravity="bottom" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 

когда ListView заполняет экран, я не могу видеть кнопки ниже него.

ответ

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="100"> 

    <LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="100" 
     android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/lvMain" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="90"> 
    </ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" 
     android:orientation="vertical" 
     android:gravity="bottom" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 
+0

Пожалуйста, также объясните, как вы исправили проблему. Только ответы на код не так полезны. – Doomsknight

+0

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

+0

О, господа, гений, спасибо вам большое – Sanzhar

0

Изменение ниже

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

    <LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" 
      /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/lvMain" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 
    </ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:gravity="bottom" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 
+0

Также объясните, как вы устранили проблему. Только ответы на код не так полезны. – Doomsknight

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

    <LinearLayout 
android:id="@+id/topLayout" 
android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
android:alignParentTop="true" 
     android:weightSum="100" 
     android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" 
      /> 
     </LinearLayout> 

    <LinearLayout 
android:id="@+id/bottomLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:gravity="bottom" 
android:alignParentBottom="true" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 

      <ListView 
       android:id="@+id/lvMain" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
android:layout_below="@+id/topLayout" 
android:layout_above="@+id/bottomLayout"> 
      </ListView> 

</RelativeLayout> 

отредактировали код. Попробуй это.

Здесь я использовал RelativeLayout, так что мы используем android:alignParentBottom="true" для нижней компоновки, которая делает макет в фиксированном виде внизу. Simillarly мы можем сделать для верхнего макета, используя android:alignParentBottom="true". Сейчас подходит к ListView, что нам нужно поместить между верхней и нижней макете я использовал следующий код для его достижения

android:layout_below="@+id/topLayout" 
    android:layout_above="@+id/bottomLayout" 

Это делает ListView всунуть между верхним и нижним макетом.

Надежда это полезно :)

+0

Пожалуйста, также объясните, как вы исправили проблему. Только ответы на код не так полезны. – Doomsknight

+1

@Doomsknight: Послушайте, я дал объяснение для кода :) – Jeevanandhan

1

Ваш макет отредактирован путем добавления веса макета. Пожалуйста, проверьте.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
    android:weightSum="1"> 

    <LinearLayout android:orientation="horizontal" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="0.1" 
        android:weightSum="100" 
        android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" 
      /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/lvMain" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.6"> 
    </ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:orientation="vertical" 
     android:layout_weight="0.3" 
     android:gravity="bottom" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 
+0

Спасибо Я пробовал ваш код, и он не работал, я не вижу вид списка вообще – Sanzhar

1

Вы должны попробовать просмотреть список с маской с весом.

Пример кода:

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

<LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.3" 
     /> 

<LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.4" 
     > 
<ListView 
       android:id="@+id/lvMain" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
      </ListView> 
</LinearLayout> 

<LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.3" 
     /> 

</LinearLayout> 

В вашей высоте фиксируется для ListView. Предполагая, что вы можете использовать представление списка как прокручиваемое в определенной высоте.

+0

Спасибо, но он не работал, теперь я не могу видеть listview вообще – Sanzhar

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