如何调整片段的边距?

时间:2019-06-12 13:52:49

标签: android android-fragments

我是Android Studio的新手,我正在研究这个项目,该项目在一页中显示2个片段。我似乎不明白为什么页边距在片段中的作用不同。

布局应该看起来像这样。请看下面:

layout 1

但是当我在选项卡中运行程序时,它将看起来像这样:

enter image description here

该项目计数被隐藏。这是代码:

fragment_purchase_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="250dp"
    android:layout_height="match_parent"
    tools:context=".Fragments.PurchaseListFragment"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:background="@color/light_gray"
        android:padding="@dimen/text_padding"
        android:gravity="center">

        <ImageView
            android:layout_width="0dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:src="@drawable/ic_delete"
            android:tint="@color/dark_text"
            android:layout_gravity="left"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="5"
            android:text="@string/item_count_title"
            android:gravity="center"
            android:textSize="@dimen/page_title"
            android:textColor="@color/dark_text"/>




    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="7"
        android:orientation="horizontal">


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="vertical"
        android:gravity="bottom"
        android:padding="@dimen/text_padding">

        <Button
            android:id="@+id/btn_paypurchasetransaction"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:background="@color/colorPrimary"
            android:text="@string/charge"
            android:textColor="@color/whiteBG"/>


    </LinearLayout>

</LinearLayout>

fragment_sales.xml,我称之为2个片段

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragments.SalesFragment"
    android:orientation="horizontal"
    android:id="@+id/customersales_content">

    <fragment
        android:id="@+id/inventory_fragment"
        android:name="com.example.devcash.Fragments.PurchaseItemListFragment"
        tools:layout="@layout/fragment_purchase_item_list"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2">

    </fragment>

    <View
        style="@style/Divider"
        android:layout_width="1dp"
        android:layout_height="wrap_content" />

    <fragment
        android:id="@+id/purchaselist_fragment"
        android:name="com.example.devcash.Fragments.PurchaseListFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        tools:layout="@layout/fragment_purchase_list">


    </fragment>


</LinearLayout>

1 个答案:

答案 0 :(得分:0)

您需要在match_parent中将宽度设置为fragment_purchase_list.xml 而不是250dp