2015-08-26 3 views
0

Я пытаюсь поместить изображение для нижней части моей страницы. Я попытался установить его с помощью android: gravity = "bottom", но мое изображение не выровнялось в нижней части страницы.Как положить изображение внизу страницы

Вот мой XML,

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/scrollView1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/LinearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <ProgressBar 
      android:id="@+id/progressBar1" 
      style="?android:attr/progressBarStyleLarge" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/login_land_layout_margin" 
      android:orientation="vertical" > 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/logo" 
       android:src="@drawable/ic_logo" /> 

      <EditText 
       android:id="@+id/codeEdit" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:ems="10" 
       android:hint="@string/code" 
       android:textColorHint="#FFFFFF" 
       android:inputType="textPassword" > 

       <requestFocus /> 
      </EditText> 

      <EditText 
       android:id="@+id/nameEdit" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:ems="10" 
       android:hint="@string/name" 
       android:textColorHint="#FFFFFF" 
       android:inputType="textPersonName" /> 

      <EditText 
       android:id="@+id/emailEdit" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:ems="10" 
       android:hint="@string/email" 
       android:textColorHint="#FFFFFF" 
       android:inputType="textEmailAddress" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="@dimen/login_land_margin_both" 
       android:layout_marginRight="@dimen/login_land_margin_both" 
       android:orientation="vertical" > 

       <Button 
        android:id="@+id/loginBtn" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginTop="@dimen/login_Land_margin_top" 
        android:background="#0f4b9b" 
        android:text="@string/login" 
        android:textColor="@color/LoginButtonColor" /> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 

     <ImageView 
      android:id="@+id/poweredBy" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/poweredby" 
      android:gravity="bottom" 
      android:scaleType="fitXY" 

      /> 
    </LinearLayout> 


</RelativeLayout> 

Вот вид моего образа.

image

Мне нужно добавить питание от изображения на нижней части страницы.

+0

На вашем экране ScrollView измените высоту, чтобы заполнить родительский андроид: layout_height = "fill_parent" –

+0

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

+0

yup like Neha сказал, что вы можете использовать выравнивание родительского дна, я думаю, что вам проще использовать RelativeLayout, если вы просто сделаете макет со страницей входа в систему – RichFounders

ответ

-1

Вы разместили ImageView виджет внутри LinearLayout. Удалите Linearlayout и используйте только виджет ImageView. Используйте следующий код для размещения изображения в нижней части экрана.

<ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/poweredby" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      android:scaleType="fitXY" /> 
+1

Добавлен андроид: fillViewport = "true" для просмотра прокрутки. Теперь работает как ожидалось. –

0

Нет необходимости в использовании, что линейная компоновка удалить что

<ImageView 
      android:id="@+id/poweredBy" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/poweredby" 
      android:layout_alignParentBottom="true" 
      android:scaleType="center" 

      /> 

К вашему Scrollview добавить android:fillViewport="true"

+0

удалена линейная компоновка. Проблема все еще существует. –

+1

Вы использовали этот код изображения –

+1

Я отредактировал мой ans check now –

2

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

android:fillViewport="true" 

и это так, вы получите результат вы хотите

+1

Ничего себе! Какой быстрый ответ. Огромное спасибо. Работает отлично. –

0

Вы можете сделать 2 вещи.

1.) Сделайте Linear Layout и установите на свойства вашего ImageView в

android:layout_below="@+id/LogInButton" 

и установить некоторые отступы сверху в этом LinearLayout, который держит этот образ.

2.) Использование колонтитула

enter image description here

Смотрите этот учебник о том, как установить FOOTER

http://www.javacodegeeks.com/2013/10/android-fixed-header-and-footer-with-scrollable-content-layout-example.html

+0

Добавлен андроид: fillViewport = "true" для просмотра прокрутки. Теперь работает как ожидалось. –

1

Использование Относительное расположение, который заполняет весь экран, вы должны быть в состоянии использовать android:layout_alignParentBottom для перемещения изображения в нижней части экрана.

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