【问题标题】:How to move buttons to the bottom of the dashboard Android Studio?如何将按钮移动到仪表板 Android Studio 的底部?
【发布时间】:2018-12-17 11:22:04
【问题描述】:

所以我正在尝试为我的应用程序设计一个仪表板,但我遇到了button 的一些问题。我想将按钮移动到我尝试使用 Android Studio 制作的应用程序的页面底部。我使用了alignparentbottom=true,但它不起作用,该按钮仅移动了一个 li'l,但不完全位于我的页面底部

这是我的按钮的代码-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/grad_bg"
android:layout_margin="9pt"
android:orientation="vertical">


<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

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

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="12pt"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_horizontal"
                        android:orientation="vertical">

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

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/btnsmile"
                                android:layout_centerHorizontal="true"
                                android:text="My Mood"

android:textColor="@color/lingkaran_smile"
                                android:textSize="14sp"
                                android:textStyle="bold" />

                            <Button
                                android:id="@+id/btnsmile"
                                style="? 
                             android:attr/progressBarStyleHorizontal"
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:layout_centerHorizontal="true"

         android:background="@drawable/lingkaran_smile"

 android:drawableTop="@drawable/ic_smile2"
                                android:indeterminate="false"
                                android:onClick="onclick"
                                android:padding="13dp"
                                android:textStyle="bold" />

                        </RelativeLayout>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

非常感谢

【问题讨论】:

    标签: android android-studio android-nestedscrollview


    【解决方案1】:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <ScrollView
        android:layout_above="@+id/bottomBtn"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:layout_height="match_parent">
            <TextView
                android:text="CONTENT HERE"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    
    </ScrollView>
    <LinearLayout
        android:orientation="horizontal"
        android:id="@+id/bottomBtn"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:weightSum="5"
        android:layout_height="wrap_content" >
        <Button
            android:layout_weight="1"
            android:text="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button
            android:layout_weight="1"
            android:text="2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button
            android:layout_weight="1"
            android:text="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button
            android:layout_weight="1"
            android:text="4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button
            android:layout_weight="1"
            android:text="5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    </RelativeLayout>
    

    【讨论】:

    • 如果您需要底部的按钮和滚动屏幕的其余部分,那么这将对您有所帮助..
    • 如果我想继续使用我的代码,是否可以将按钮移动到底部?我在水平位置制作了 5 个按钮
    • 在你的 xml 中有很多布局.. 不需要这些所有布局.. 如果你需要在底部放 5 个按钮告诉我我为你提供 xml..
    • 是的,如果你能给我提供更简单和更少布局的xml代码,那对我帮助很大,非常感谢
    • 抱歉,我使用了 android:layout_margin="10dp" 的更新,现在每个按钮都有距离并且看起来更好。再次感谢您的帮助 Bro.God Bless and have a good day
    猜你喜欢
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 2016-02-24
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多