2016-10-24 90 views
0

當我將片段替換爲FrameLayout時,尺寸不適合。例如我在頁面的按鈕是主要佈局對象下 enter image description here activity_main佈局代碼根據圖片將android片段替換爲幀佈局的fiil_parent

<?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(); 
+0

FILL_PARENT已被棄用,FILL_PARENT和match_parent完全相同 – MichaelStoddart

+0

@MichaelStoddart耶。對。但我使用math_parent,我又有這個問題 –

回答

0

你必須使用父佈局作爲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> 
+0

我這樣做。但我再次遇到這個問題 –

+0

如果你分享你的代碼,我會檢查。 –