第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

修復(fù)內(nèi)容小的時(shí)候在屏幕底部的按鈕,如果內(nèi)容大到可以占據(jù)整個(gè)屏幕,則在內(nèi)容的底部

修復(fù)內(nèi)容小的時(shí)候在屏幕底部的按鈕,如果內(nèi)容大到可以占據(jù)整個(gè)屏幕,則在內(nèi)容的底部

白衣非少年 2021-11-03 10:46:12
為此,我正在將 android studio 與 java 一起使用。問(wèn)題說(shuō)明 修復(fù)內(nèi)容小的時(shí)候在屏幕底部的按鈕,如果內(nèi)容大到可以占據(jù)整個(gè)屏幕,則在內(nèi)容的底部。1.當(dāng)內(nèi)容較小時(shí),當(dāng)內(nèi)容足夠小以占據(jù)整個(gè)屏幕時(shí),我想在屏幕底部固定兩個(gè)按鈕。2.當(dāng)內(nèi)容很大時(shí)當(dāng)內(nèi)容足夠大到占據(jù)整個(gè)屏幕時(shí),它應(yīng)該出現(xiàn)在整個(gè)內(nèi)容的底部。當(dāng)用戶向下滾動(dòng)時(shí),按鈕應(yīng)該出現(xiàn)。在這張圖片中,如果我想點(diǎn)擊按鈕,我已經(jīng)完全向下滾動(dòng)了。這是第二個(gè)實(shí)現(xiàn)的代碼<?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_width="match_parent"    android:layout_height="wrap_content">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical">        <android.support.v7.widget.RecyclerView            android:id="@+id/eachWord"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_margin="8dp"            android:scrollbars="vertical" />        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="vertical">            <Button                android:id="@+id/perWordHistory"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:text="History" />            <Button                android:id="@+id/perWordBack"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:text="Back" />        </LinearLayout>    </LinearLayout></ScrollView></RelativeLayout>我想使用一個(gè) xml 文件實(shí)現(xiàn)這兩種方案,但是當(dāng)內(nèi)容很小時(shí)使用第二種實(shí)現(xiàn),然后按鈕位于內(nèi)容下方而不是屏幕底部。
查看完整描述

1 回答

?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

minHeight 屬性是回答這個(gè)問(wèn)題的關(guān)鍵。


我首先得到應(yīng)用程序屏幕大小,然后從中減去按鈕和工具欄大小。然后我將其設(shè)置為我的內(nèi)容所在的線性布局的最小尺寸。


我使用了 onWindowFocusChanged 函數(shù),因?yàn)橛袝r(shí)布局可能需要時(shí)間才能完全加載,因此獲取按鈕高度可能會(huì)失敗。


@Override

public void onWindowFocusChanged(boolean hasFocus) {

    super.onWindowFocusChanged(hasFocus);


    Configuration configuration = getResources().getConfiguration();//returns the app screen size.

    int screenHeightDp = configuration.screenHeightDp-56;// 56 is the max height of the android toolbar. 

    float density = this.getResources().getDisplayMetrics().density; 



    screenHeightDp = (int)(screenHeightDp*density);//changes the dp to pixel



    Button perWordHistory = findViewById(R.id.perWordHistory);

    int heightOfButton = perWordHistory.getHeight()*2; // as I have two buttons

    screenHeightDp = screenHeightDp - heightOfButton;


    LinearLayout linearLayout = findViewById(R.id.layoutContainingRecycleView);

    linearLayout.setMinimumHeight(screenHeightDp);

}

這是經(jīng)過(guò)一些更改后的布局代碼。


<?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_width="match_parent"

        android:layout_height="wrap_content">

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:orientation="vertical">


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:orientation="vertical"

            android:id="@+id/layoutContainingRecycleView">


            <android.support.v7.widget.RecyclerView

                android:id="@+id/eachWord"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:layout_margin="8dp"

                android:scrollbars="vertical" />

        </LinearLayout>


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:orientation="vertical">


            <Button

                android:id="@+id/perWordHistory"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="@string/title_history" />



            <Button

                android:id="@+id/Help"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="@string/help" />


        </LinearLayout>




    </LinearLayout>



    </ScrollView>




</RelativeLayout>


查看完整回答
反對(duì) 回復(fù) 2021-11-03
  • 1 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)