为什么按钮没有显示在分割布局的底部?

时间:2017-05-01 14:05:17

标签: java android

直升机,

我的代码:

<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>

我的问题是:

屏幕上不显示下面的两个按钮button6和button7。在Android工作室他们是,但不是在我的手机上。

我做错了什么?

This is displayed in android studio gui builder

This is display on android emulator or real device

1 个答案:

答案 0 :(得分:0)

嗯......我不知道它是否是最好的解决方案。

但是我将第二个线性布局的底部填充设置为:

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);