簡體   English   中英

Android片段布局問題

[英]Android fragment layout issue

在我的android應用程序中,我要從另一個Sherlock片段中替換Sherlock片段。 (讓我們說B中的A)我使用了以下代碼進行替換

   FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
   Fragment fragment = new AddNewRaveFragment();
   ft.replace(R.id.raves_frame, fragment,"NewFragmentTag");
   ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
   ft.addToBackStack(null);
   ft.commit();

列出我用於片段A的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<FrameLayout
    android:id="@+id/raves_frame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="114dp"
    android:layout_marginTop="69dp" >
</FrameLayout>


</RelativeLayout>

但是當我運行程序時,它顯示布局向左偏移 在此處輸入圖片說明

這是我用於布局B的代碼:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

</LinearLayout>

那么如何使它正確顯示在屏幕上呢? 謝謝

問題是因為您在FrameLayout留有邊距。 只需刪除此行android:layout_marginLeft="114dp"也刪除利潤率最高的android:layout_marginTop="69dp"從而留出多余的空間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM