简体   繁体   中英

layout_alignParentBottom does not work

I added an image in my android project. I tried to display it in the bottom of the scree with the following xml code in the image layout:

    android:layout_alignParentBottom="true"
    android:layout_marginRight="60dp"

But the image keep displaying in the up.

What is the problem here ?

My android version is 4.1

here after the whole xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
/*
   Session screen layout

   Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz

   This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 
   If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
 -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/session_root_view"
    >

    <!-- childs are specified bottom-up so that we have a correct z-order in our final layout -->
    <android.inputmethodservice.KeyboardView
        android:id="@+id/extended_keyboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:visibility="gone"
        />

    <com.freerdp.freerdpcore.presentation.ScrollView2D
        android:id="@+id/sessionScrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/extended_keyboard"
        android:scrollbars="horizontal|vertical"
        android:layout_alignParentTop="true"
        android:fillViewport="true"
        android:drawingCacheQuality="low"
        android:isScrollContainer="true"
        >

        <com.freerdp.freerdpcore.presentation.SessionView
            android:id="@+id/sessionView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:drawingCacheQuality="low"
            />

    </com.freerdp.freerdpcore.presentation.ScrollView2D>        

    <com.freerdp.freerdpcore.presentation.TouchPointerView
        android:id="@+id/touchPointerView"
        android:layout_width="match_parent"         
        android:layout_height="match_parent"
        android:src="@drawable/touch_pointer_default"
        android:visibility="invisible"
        />

    <com.freerdp.freerdpcore.presentation.TxxTouchPointerView
        android:id="@+id/tmmTouchPointerView"
        android:layout_width="match_parent"         
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="60dp"
        android:src="@drawable/tmm_touch_pointer_default"
        android:visibility="invisible"
        />

    <android.widget.ZoomControls
        android:id="@+id/zoomControls"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/sessionScrollView"
        android:layout_centerHorizontal="true"
        />

    <android.inputmethodservice.KeyboardView
        android:id="@+id/extended_keyboard_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:visibility="gone"
        android:layout_centerHorizontal="true"      
        />   

</RelativeLayout>

Assuming this is the image in question

<com.freerdp.freerdpcore.presentation.TxxTouchPointerView
    android:id="@+id/tmmTouchPointerView"
    android:layout_width="match_parent"         
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_marginRight="60dp"
    android:src="@drawable/tmm_touch_pointer_default"
    android:visibility="invisible"
    />

The layout_height is match_parent . This means that it will be as vertically large as the parent so layout_alignParentBottom="true" means nothing. Try with:

        android:layout_height="wrap_content"

将图像放在相对布局中

You are setting its layout_height="match_parent" which means it always gets full height of its parent (your case is screen height), just set it to layout_height="wrap_content" . Same thing with layout_width if needed

See this

    <com.freerdp.freerdpcore.presentation.TxxTouchPointerView
    android:id="@+id/tmmTouchPointerView"
    android:layout_width="wrap_content"         
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginRight="60dp"
    android:src="@drawable/tmm_touch_pointer_default"
    android:visibility="invisible"
    />

I guess the RelativeLayout itself is not set layout_height="match_parent" .

update:

<RelativeLayout
    layout_height="match_parent"
    (...)
    >

    <ImageView
        layout_height="wrap_content"
        layout_alignParentBottom="true"
        (...)
        />

</RelativeLayout>

You can use a LinearLayout instead, and set gravity to bottom as follows:

android:gravity="bottom"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM