Как настроить поле в фрагментах? - PullRequest
0 голосов
/ 12 июня 2019

Я новичок в Android-студии и работаю над этим проектом, который показывает 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>

фрагмент_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 голосов
/ 12 июня 2019

вам нужно установить ширину match_parent в fragment_purchase_list.xml вместо 250dp

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...