如何将View Group放在屏幕底部

时间:2014-05-12 08:09:19

标签: android android-layout

您好我正在设计我的应用程序的一个屏幕,我需要将完整的最后LinearLayout放在屏幕的底部,这意味着ImageViews的{​​{1}}应该出现在底部但目前他们没有放置,你能不能看看这可能是什么原因。这是怎样的正确方法

LinearLayout

目前它看起来像这样,我想要从屏幕底部显示所有三个<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.audiostreet.LoginActivity$PlaceholderFragment" > <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/logo_dans_ma_rue" /> <com.example.customview.TextViewWithCustomFont android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/login_screen_app_tex_vertical_margin" android:gravity="center" android:text="@string/app_name" android:textSize="@dimen/login_screen_app_text_size" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/login_main_drawable" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:gravity="bottom" android:orientation="vertical" > <ImageView android:id="@+id/facebookButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/buttons_vertical_margin" android:adjustViewBounds="true" android:contentDescription="@null" android:src="@drawable/fb_button" /> <ImageView android:id="@+id/twitterButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/buttons_vertical_margin" android:adjustViewBounds="true" android:contentDescription="@null" android:src="@drawable/twitter_button" /> <ImageView android:id="@+id/emailButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/buttons_vertical_margin" android:adjustViewBounds="true" android:contentDescription="@null" android:src="@drawable/email_button" /> </LinearLayout> </LinearLayout> </ScrollView>

平板电脑7英寸

enter image description here

平板电脑10英寸

enter image description here

2 个答案:

答案 0 :(得分:0)

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.audiostreet.LoginActivity$PlaceholderFragment" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/loading" />

    <com.example.customview.TextViewWithCustomFont
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/app_name"
        android:textSize="15dp" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/loading" />
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
    ></LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:gravity="bottom"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/facebookButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:contentDescription="@null"
            android:src="@drawable/loading" />

        <ImageView
            android:id="@+id/twitterButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:contentDescription="@null"
            android:src="@drawable/loading" />

        <ImageView
            android:id="@+id/emailButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:contentDescription="@null"
            android:src="@drawable/loading" />
    </LinearLayout>
</LinearLayout>

你真的需要ScrollView吗?如果不是这样尝试,否则滚动视图将尝试获得最小视图高度,并且我的占位符将被展平。

替代方法是将按钮放在ScrollView下。

我看到的最后一个解决方案,如果你真的需要在scrollView中做任何事情,那么试着生成你自己的LinearLayout而不是自己放置视图。

答案 1 :(得分:0)

// try this way,hope this will help you...

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.audiostreet.LoginActivity$PlaceholderFragment" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/logo_dans_ma_rue" />

        <com.example.customview.TextViewWithCustomFont
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/login_screen_app_tex_vertical_margin"
            android:gravity="center"
            android:text="@string/app_name"
            android:textSize="@dimen/login_screen_app_text_size" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/login_main_drawable" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="bottom"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/facebookButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/buttons_vertical_margin"
                android:adjustViewBounds="true"
                android:contentDescription="@null"
                android:src="@drawable/fb_button" />

            <ImageView
                android:id="@+id/twitterButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/buttons_vertical_margin"
                android:adjustViewBounds="true"
                android:contentDescription="@null"
                android:src="@drawable/twitter_button" />

            <ImageView
                android:id="@+id/emailButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/buttons_vertical_margin"
                android:adjustViewBounds="true"
                android:contentDescription="@null"
                android:src="@drawable/email_button" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>