2013-08-29 5 views
2

У меня есть xml-файл, который содержит ScrollView и внутри есть LinearLayout; эта схема также содержит больше 2 макета:Android layout gravity не работает

первого, где данные будут добавлены динамически

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

Но гравитация не работает, я пробовал и gravity, и layout_gravity, но никто не работает, все макеты установлены, чтобы заполнить родителя, так почему это происходит?

Распространение авторских прав должно быть внутри ScrollView, но в нижней части экрана, даже если ScrollView пуст (1-й макет).

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:id="@+id/istoricLayout" 
    android:visibility="visible" > 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

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

      <LinearLayout 
       android:id="@+id/istoric" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" //here I'm trying to move this at the buttom 
       android:orientation="vertical" > 

       <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="@dimen/thick_bar_height" 
        android:layout_marginBottom="@dimen/bar_vertical_space" 
        android:layout_marginTop="@dimen/bar_vertical_space" 
        android:background="@color/white" /> 

       <Button 
        android:id="@+id/versiuneaCompleta" 
        android:layout_width="250dp" 
        android:layout_height="30dp" 
        android:layout_gravity="center" 
        android:layout_marginBottom="10dp" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:background="@color/color2" 
        android:text="Vizioneaza versiunea completa" 
        android:textAlignment="center" 
        android:textColor="@color/white" 
        android:textSize="15dp" /> 

       <RelativeLayout 
        android:layout_width="250dp" 
        android:layout_height="30dp" 
        android:layout_gravity="center" 
        android:layout_marginBottom="10dp" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:background="@color/white" > 

        <ImageView 
         android:layout_width="30dp" 
         android:layout_height="30dp" 
         android:layout_alignParentRight="true" 
         android:adjustViewBounds="true" 
         android:src="@drawable/support_right_icon" /> 

        <ImageView 
         android:layout_width="30dp" 
         android:layout_height="30dp" 
         android:layout_alignParentLeft="true" 
         android:adjustViewBounds="true" 
         android:src="@drawable/support_left_icon" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerInParent="true" 
         android:background="@color/white" 
         android:text="Support +40.XXX.XXX.XXX" 
         android:textAlignment="center" 
         android:textColor="@color/color2" 
         android:textSize="15dp" /> 
       </RelativeLayout> 

       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:orientation="horizontal" > 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Politica de condidentialitate ·" 
         android:textColor="@color/white" 
         android:textSize="10dp" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text=" Despre noi ·" 
         android:textColor="@color/white" 
         android:textSize="10dp" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text=" Contact" 
         android:textColor="@color/white" 
         android:textSize="10dp" /> 
       </LinearLayout> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:text="© 2013 Artcos Design. All Rights Reserved" 
        android:textColor="@color/copyRightColor" 
        android:textSize="10dp" /> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 
+1

Это хорошо, что вы предоставили свой номер поддержки. Я позвоню вам посреди ночи: P – gunar

+1

oww, поддельный номер ... –

+1

ну тогда у кого-то есть этот номер: D – gunar

ответ

1

Переместить текстовое изображение, под прокруткой. Вы используете гравитацию неправильно.

Я предполагаю, что вы хотите, чтобы ваши авторские права были исправлены внизу.

Гравитация используется для отображения содержимого вида определенными способами. или как позиционировать представление, но он не изменит иерархию представлений.

 </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:text="© 2013 Artcos Design. All Rights Reserved" 
    android:textColor="@color/copyRightColor" 
    android:textSize="10dp" /> 

</LinearLayout> 

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

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1" > 
+0

, но я хочу авторское право должно быть в «ScrollView», но если ScrollView пуст (или очень мало элементов), появится внизу. –

+0

Я начинаю думать, что это невозможно сделать только с одним xml –

+0

@MihaiBratulescu Затем поместите свое 'textview' после' linearlayout', находящегося внутри 'scrollview', и сделайте' linearlayout' height = 0dip и вес = 1, как показано выше. Это приведет к тому, что оно займет столько места, сколько доступно, но оставит пространство для ваших авторских прав. (если нет места, поэтому вам нужно прокрутить, чтобы увидеть его) – Doomsknight

2

На основе комментариев к ответу @ Doomsknight, установите android:fillViewPort="true" на ScrollView.

Атрибут высоты для дочернего элемента прокрутки игнорируется (если бы он был соблюден, весь вид прокрутки был бы бесполезен). Установка fillViewPort="true" делает дочерний элемент прокрутки расширяться до высоты родителя, если он меньше высоты родителя, и в противном случае атрибут ничего не делает. Таким образом, ваш ребенок LinearLayout в представлении прокрутки будет как минимум ростом, чем родительский вид прокрутки, что делает гравитацию работать так, как вы хотите.

Кроме того, сделать ребенку LinearLayout высот в wrap_content и назначить первый LinearLayout ненулевая layout_weight. Вы также можете удалить bottomlayout_gravity.

+0

Я не знаю, почему, но он не работает. Это звучит неплохо в теории, но на практике это не так хорошо. –

2

Изменить все, что нужно:

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

    <LinearLayout 
     android:id="@+id/bottomLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="@dimen/thick_bar_height" 
      android:layout_marginBottom="@dimen/bar_vertical_space" 
      android:layout_marginTop="@dimen/bar_vertical_space" 
      android:background="@color/white" /> 

     <Button 
      android:id="@+id/versiuneaCompleta" 
      android:layout_width="250dp" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:background="@color/color2" 
      android:text="Vizioneaza versiunea completa" 
      android:textAlignment="center" 
      android:textColor="@color/white" 
      android:textSize="15dp" /> 

     <RelativeLayout 
      android:layout_width="250dp" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:background="@color/white" > 

      <ImageView 
       android:layout_width="30dp" 
       android:layout_height="30dp" 
       android:layout_alignParentRight="true" 
       android:adjustViewBounds="true" 
       android:src="@drawable/support_right_icon" /> 

      <ImageView 
       android:layout_width="30dp" 
       android:layout_height="30dp" 
       android:layout_alignParentLeft="true" 
       android:adjustViewBounds="true" 
       android:src="@drawable/support_left_icon" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:background="@color/white" 
       android:text="Support +40.766.154.894" 
       android:textAlignment="center" 
       android:textColor="@color/color2" 
       android:textSize="15dp" /> 
     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:orientation="horizontal" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Politica de condidentialitate ·" 
       android:textColor="@color/white" 
       android:textSize="10dp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text=" Despre noi ·" 
       android:textColor="@color/white" 
       android:textSize="10dp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text=" Contact" 
       android:textColor="@color/white" 
       android:textSize="10dp" /> 
     </LinearLayout> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="© 2013 Artcos Design. All Rights Reserved" 
      android:textColor="@color/copyRightColor" 
      android:textSize="10dp" /> 
    </LinearLayout> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/bottomLayout" > 

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

      <LinearLayout 
       android:id="@+id/istoric" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

EDIT Установка ссылки размеры, цвета и изображения на что-то значимое, расположение выглядит, как показано ниже изображения (для ясности ScrollView имеет красный фон и bottomLayout имеет желтый фон). enter image description here

Как видите, bottomLayout находится внизу.

+0

Я выгляжу так, как должен, но если у ScrollView будет много элементов, все равно будет выглядеть так, как будто макет авторского права находится внутри ScrollView, а не всегда внизу? Я не могу это проверить, так как API, который мне нужен, все еще находится в разработке, и это задача для другого парня. –

+0

Используйте некоторые данные. – gunar

+0

Ну, это не добавление его в нижней части прокрутки, но я передумал и предпочитаю его таким образом. Однако вопрос все еще не ответил, поэтому продолжайте пытаться. Я еще не принял ответа. –

2

Проверить эту ссылку, он содержит объяснение вашей проблемы:

http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/

андроид: fillViewport в ScrollView должна быть установлена ​​истина, которая позволяет дочернее расширить себя, чтобы заполнить ScrollView-х высота. Затем выберите один дочерний элемент, который будет расширен, чтобы заполнить пустое пространство и установить его layout_weight в 1 (при условии использования LinearLayout). Этот элемент, как правило, тот, что находится над виджетами, который предназначен для размещения прямо внизу.

файл XML должен выглядеть следующим образом:

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true"> 

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

     <!-- widget 1 --> 
     <!-- widget 2 --> 
     <!-- ... --> 
     <!-- widget n --> 

     <!-- this widget expands to fill the empty space --> 
     <TextView 
      android:layout_height="fill_parent" 
      android:layout_weight="1"> 
     </TextView> 

     <!-- this copyright layout is going to be placed rock bottom --> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="© 2013 Artcos Design. All Rights Reserved" 
      android:textColor="@color/copyRightColor" 
      android:textSize="10dp" /> 

    </LinearLayout> 

</ScrollView> 
Смежные вопросы