#android #android-layout #android-fragments #android-framelayout
#Android #android-layout #android-фрагменты #android-framelayout
Вопрос:
согласно изображению, когда я заменяю свой фрагмент в FrameLayout, размер не подходит. например, моя кнопка на странице находится под основным объектом макета activity_main layout code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@ id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:orientation="vertical"
tools:context="com.teskaco.bbpos.Activities.MainActivities.MainActivity">
<com.alirezaafkar.toolbar.Toolbar
android:id="@ id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:paddingTop="@dimen/app_bar_top_padding"
app:direction="rtl"
app:font="@string/font_path"
app:navigationIcon="@drawable/m_e_n_u"
app:optionsMenu="@menu/main_menu">
<com.teskaco.bbpos.CustumView.CustomTextView
android:id="@ id/main_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/psp_name"
android:textColor="@color/colorControlNormal"
android:textSize="@dimen/small_text_size" />
</com.alirezaafkar.toolbar.Toolbar>
<FrameLayout
android:id="@ id/main_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<include
android:id="@ id/buttonPanel"
layout="@layout/main_top_bar" />
</LinearLayout>
мой XML-код макета фрагмента
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@ id/fragment_pay"
tools:context="com.teskaco.bbpos.Activities.MainActivities.PayBillFragment">
<com.teskaco.bbpos.CustumView.CustomButton
android:id="@ id/send_button"
style="@style/LightRaiseColorButtonRippleStyle"
android:layout_width="@dimen/_300sdp"
android:layout_height="@dimen/button_height"
android:layout_gravity="center"
android:layout_marginTop="@dimen/_4sdp"
android:gravity="center"
android:text="@string/send_button"
android:textColor="@color/disable_button"
android:textSize="@dimen/button_text_size" />
<LinearLayout
android:orientation="vertical"
android:gravity="center|top"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/_6sdp"
android:background="@color/white">
<RelativeLayout
android:id="@ id/skech_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:background="@color/white">
<ImageView
android:id="@ id/skech_image"
android:layout_width="@dimen/_90sdp"
android:layout_height="@dimen/_101sdp"
android:layout_centerHorizontal="true"
android:src="@drawable/ghabz" />
<com.teskaco.bbpos.CustumView.CustomTextView
android:id="@ id/ghabz_textview"
android:layout_width="@dimen/_250sdp"
android:layout_height="wrap_content"
android:layout_below="@ id/skech_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/_21sdp"
android:gravity="center"
android:text="@string/bill_text"
android:textSize="@dimen/mediume_text_size" />
</RelativeLayout>
<LinearLayout
android:id="@ id/name_layout"
android:layout_width="@dimen/_250sdp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_8sdp"
android:background="@drawable/raduis_bg_edit_text"
android:orientation="horizontal">
<com.teskaco.bbpos.CustumView.CustomTextInputLayout
android:id="@ id/shenase_text_input_layout"
android:layout_width="@dimen/_210sdp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_5sdp"
android:theme="@style/TextLabel">
<com.teskaco.bbpos.CustumView.CustomEditText
android:id="@ id/id_bill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/_6sdp"
android:layout_marginRight="@dimen/_6sdp"
android:layout_marginTop="@dimen/_4sdp"
android:background="@null"
android:gravity="right"
android:hint="@string/id_Bill_text"
android:inputType="number"
android:paddingBottom="@dimen/_4sdp"
android:textColor="@color/green_blue"
android:textSize="@dimen/defult_text_size" />
</com.teskaco.bbpos.CustumView.CustomTextInputLayout>
<android.support.v7.widget.AppCompatImageView
android:layout_width="@dimen/_16sdp"
android:layout_height="@dimen/_12sdp"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/_5sdp"
android:background="@drawable/user_id" />
</LinearLayout>
<LinearLayout
android:id="@ id/name_layout1"
android:layout_width="@dimen/_250sdp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_8sdp"
android:background="@drawable/raduis_bg_edit_text"
android:orientation="horizontal">
<com.teskaco.bbpos.CustumView.CustomTextInputLayout
android:id="@ id/payment_text_input_layout"
android:layout_width="@dimen/_210sdp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_5sdp"
android:theme="@style/TextLabel">
<com.teskaco.bbpos.CustumView.CustomEditText
android:id="@ id/id_payment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/_6sdp"
android:layout_marginRight="@dimen/_6sdp"
android:layout_marginTop="@dimen/_4sdp"
android:background="@null"
android:gravity="right"
android:hint="@string/id_payment_text"
android:inputType="number"
android:paddingBottom="@dimen/_4sdp"
android:textColor="@color/green_blue"
android:textSize="@dimen/defult_text_size" />
</com.teskaco.bbpos.CustumView.CustomTextInputLayout>
<android.support.v7.widget.AppCompatImageView
android:layout_width="@dimen/_16sdp"
android:layout_height="@dimen/_12sdp"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/_5sdp"
android:background="@drawable/user_id" />
</LinearLayout>
<com.teskaco.bbpos.CustumView.CustomButton
android:id="@ id/barcode_reader"
style="@style/GrayRaiseColorButtonRippleStyle"
android:layout_width="@dimen/_250sdp"
android:layout_height="@dimen/button_height"
android:layout_gravity="center"
android:layout_marginTop="@dimen/_24sdp"
android:gravity="center"
android:text="@string/barcode_reader_text"
android:textColor="@color/disable_button"
android:textSize="@dimen/button_text_size" />
</LinearLayout>
</LinearLayout>
замените код
fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.main_fragment, PayBillFragment.newInstance()).addToBackStack("PayBill").commit();
Комментарии:
1. fill_parent устарел, fill_parent и match_parent точно такие же
2. @MichaelStoddart да. правильно. но я использую math_parent, и у меня снова возникает эта проблема
Ответ №1:
Вы должны использовать родительский макет в качестве RelativeLayout и использовать свойство RelativeLayout.
<com.alirezaafkar.toolbar.Toolbar
android:id="@ id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:paddingTop="@dimen/app_bar_top_padding"
app:direction="rtl"
app:font="@string/font_path"
app:navigationIcon="@drawable/m_e_n_u"
app:optionsMenu="@menu/main_menu">
<com.teskaco.bbpos.CustumView.CustomTextView
android:id="@ id/main_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/psp_name"
android:textColor="@color/colorControlNormal"
android:textSize="@dimen/small_text_size" />
</com.alirezaafkar.toolbar.Toolbar>
<FrameLayout
android:id="@ id/main_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@ id/buttonPanel" />
<include
android:id="@ id/buttonPanel"
layout="@layout/tab_bottom_menus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Комментарии:
1. я делаю это. но опять у меня эта проблема