如何使下,滚动型静态按钮?静态、按钮

2023-09-06 04:43:13 作者:酒杯中的大海

我有以下的XML。我试图做一个静态的按钮,我的滚动型下方。我试着设置权,设置按钮是滚动视图下方,等有人可以给我一个办法,我可以拿到按钮留在底部和滚动型只需要在屏幕的中间?

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>



    <的LinearLayout
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID / menuButtons
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:重力=center_horizo​​ntal>

        <按钮的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            机器人:ID =@ + ID / newItems
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=新项目/>
        <按钮的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            机器人:ID =@ + ID /类别
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=分类/>

    < / LinearLayout中>


    <滚动型
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID / contentScroller
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ ID / menuButtons>

        < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            机器人:方向=垂直
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT>


            < TableLayout
                的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT
                机器人:stretchColumns =1>


                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    < ImageView的
                        机器人:SRC =@可绘制/闪存棒/>中
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=拇指驱动器
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    < ImageView的
                        机器人:SRC =@可绘制/笔记本电脑/>
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=笔记本电脑
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    < ImageView的
                        机器人:SRC =@可绘制/ SD卡/>
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=SD卡
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=其它
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=其它
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=其它
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=其它
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=其它
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
                <的TableRow安卓layout_marginTop =5dip
                          机器人:layout_marginBottom =5dip>
                    <的TextView
                        机器人:layout_column =1
                        机器人:文本=其它
                        机器人:填充=3dip
                        机器人:TEXTSIZE =20dip/>
                < /的TableRow>
            < / TableLayout>
        < / LinearLayout中>
    < /滚动型>

    <按钮
        机器人:ID =@ + ID /提交
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:文本=提交新项目
        机器人:layout_below =@ ID / contentScroller/>

< / RelativeLayout的>
 

解决方案

使用 RelativeLayout的。先从按钮在底部,和定位滚动型上面的按钮

相对布局 - Android开发者

 < RelativeLayout的
  (...)>

    <的LinearLayout机器人:ID =@ + ID / LL1
        机器人:layout_alignParentTop =真
        (...)/>

    <按钮机器人:ID =@ + ID /按钮
        机器人:layout_alignParentBottom =真
        (...)/>

    <滚动型
         机器人:layout_above =@ ID /按钮
         机器人:layout_below =@ ID / LL1
         (...)/>

< / RelativeLayout的>
 
自动复位按钮

这样的事情。写出了我的头,所以可能会出现一些错误。

I have the following XML. I'm trying to make a static button underneath my ScrollView. I've tried to set weights, set the button to be below the scrollview, etc. Can someone give me a way that I can get the button to stay at the bottom and the scrollview only take up the middle of the screen?

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



    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/menuButtons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">

        <Button xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/newItems"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Items" />
        <Button xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/categories"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Categories" />

    </LinearLayout>


    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/contentScroller"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/menuButtons">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">


            <TableLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1" >


                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip" >
                    <ImageView
                        android:src="@drawable/thumbdrive"/>"
                    <TextView
                        android:layout_column="1"            
                        android:text="Thumb Drives"            
                        android:padding="3dip" 
                        android:textSize="20dip"/>
                </TableRow>
                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip">
                    <ImageView
                        android:src="@drawable/laptop"/>
                    <TextView
                        android:layout_column="1"
                        android:text="Laptops"
                        android:padding="3dip"
                        android:textSize="20dip"/>
                </TableRow>
                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip">
                    <ImageView
                        android:src="@drawable/sdcard"/>
                    <TextView
                        android:layout_column="1"
                        android:text="SD Cards"
                        android:padding="3dip"
                        android:textSize="20dip"/>
                </TableRow>
                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip">
                    <TextView
                        android:layout_column="1"
                        android:text="Other"
                        android:padding="3dip"
                        android:textSize="20dip"/>
                </TableRow>
                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip">
                    <TextView
                        android:layout_column="1"
                        android:text="Other"
                        android:padding="3dip"
                        android:textSize="20dip"/>
                </TableRow>
                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip">
                    <TextView
                        android:layout_column="1"
                        android:text="Other"
                        android:padding="3dip"
                        android:textSize="20dip"/>
                </TableRow>
                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip">
                    <TextView
                        android:layout_column="1"
                        android:text="Other"
                        android:padding="3dip"
                        android:textSize="20dip"/>
                </TableRow>
                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip">
                    <TextView
                        android:layout_column="1"
                        android:text="Other"
                        android:padding="3dip"
                        android:textSize="20dip"/>
                </TableRow>
                <TableRow android:layout_marginTop="5dip"
                          android:layout_marginBottom="5dip">
                    <TextView
                        android:layout_column="1"
                        android:text="Other"
                        android:padding="3dip"
                        android:textSize="20dip"/>
                </TableRow>
            </TableLayout>
        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Submit New Item"
        android:layout_below="@id/contentScroller"/>

</RelativeLayout>

解决方案

Use a RelativeLayout. Start with the Button on the bottom, and position the ScrollView above the Button.

Relative Layout - Android Developers

<RelativeLayout
  (...)>

    <LinearLayout android:id="@+id/ll1"
        android:layout_alignParentTop="true"
        (...)/>

    <Button android:id="@+id/button"
        android:layout_alignParentBottom="true"
        (...)/>

    <ScrollView
         android:layout_above="@id/button"
         android:layout_below="@id/ll1"
         (...)/>

</RelativeLayout>

Something like this. Written out of my head, so some errors may occur.