简体   繁体   English

为什么按钮未显示在拆分布局的底部?

[英]Why the buttons are not shown at the bottom of splitted layout?

Helo, 直升机,

my code: 我的代码:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1.0"
>

<LinearLayout
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.4"
    android:padding="20sp"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/colorAccent"
        android:orientation="vertical">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="3sp"
            android:background="@color/colorAccent"
            >
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="1"
                >

                <TextView
                    android:id="@+id/textView32"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="@string/accounts"
                    android:textAllCaps="false"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </TableRow>
        </TableLayout>

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10sp"
            android:background="@color/colorAccent">
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <TextView
                    android:id="@+id/textView_Account_Name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/account"
                    android:textStyle="bold"
                    android:paddingRight="10sp"
                    />
                <TextView
                    android:id="@+id/textView_Account_Description"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/account_description"
                    android:textStyle="bold"
                    android:paddingRight="10sp"
                    />
                <TextView
                    android:id="@+id/textView_Account_Sum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/account_sum"
                    android:textStyle="bold"
                    />

            </TableRow>
        </TableLayout>

        <!-- Scrollable Area 1 Begin -->
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="none"
            android:layout_weight="1"
            android:fillViewport="true">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:background="@color/colorAccent">
                <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:padding="10sp">
                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    </TableRow>
                </TableLayout>
            </LinearLayout>
        </ScrollView>
        <!-- Scrollable Area 1 End -->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Konto hinzufügen" />

            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Konto löschen" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/scrollView2"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.6"
    android:gravity="center|bottom"
    android:paddingBottom="10sp"
    android:paddingLeft="20sp"
    android:paddingRight="20sp"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/colorAccent2"
        android:orientation="vertical"
        android:gravity="center|bottom">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent2"
            android:padding="3sp">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="1">

                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="@string/account_input_output"
                    android:textAllCaps="false"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </TableRow>
        </TableLayout>

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent2"
            android:padding="10sp">

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

                <TextView
                    android:id="@+id/textView_IO_Date"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingRight="10sp"
                    android:text="@string/account_io_date"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textView_IO_Nr"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingRight="10sp"
                    android:text="@string/account_io_description"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textView_IO_Ausgabe"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingRight="10sp"
                    android:text="@string/account_io_ausgabe"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textView_IO_Eingabe"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingRight="10sp"
                    android:text="@string/account_io_eingabe"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textView_IO_Sum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/account_sum"
                    android:textStyle="bold" />
            </TableRow>
        </TableLayout>


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:fillViewport="true"
            android:scrollbars="none">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorAccent2"
                android:orientation="vertical">

                <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:padding="10sp">

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

                    </TableRow>
                </TableLayout>
            </LinearLayout>
        </ScrollView>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent2"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Transaktion hinzufügen"

                />

            <Button
                android:id="@+id/button7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Transaktion löschen" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

My problem is: 我的问题是:

The two buttons button6 and button7 below aren't displayed on screen. 屏幕上未显示下面的两个按钮button6和button7。 On android studio they are, but not on my mobile phone. 在android studio上,但不在我的手机上。

What am I doing wrong? 我究竟做错了什么?

This is displayed in android studio gui builder 这显示在android studio gui生成器中

This is display on android emulator or real device 显示在android模拟器或真实设备上

Hmm... I don't know if it's the best solution. 嗯...我不知道这是否是最好的解决方案。

But I set the bottom padding of the second linear layout to: 但是我将第二个线性布局的底部填充设置为:

20sp + 20 sp + black stripe on the bottom sp + 20 sp

Context context = rootView.getContext();
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
int width = resources.getDimensionPixelSize(resourceId);

LinearLayout l = (LinearLayout)rootView.findViewById(R.id.scrollView2);

float density = context.getResources().getDisplayMetrics().density;
int paddingDp = (int)(20 * density);

l.setPadding(paddingDp, 0, paddingDp, paddingDp + paddingDp + width);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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