我試圖解決這一段時間,並找不到問題。我有一個片段,我有ProgressBar中心。這裏是fragment的xml文件內容。Android中的片段內容位置
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<LinearLayout
android:id="@+id/details_form"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false"
android:orientation="vertical"
android:visibility="gone" >
...
</LinearLayout>
</merge>
我也有活動,我只是將此片段添加到活動中。下面是活動
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/details_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
tools:context=".MyActivity"
tools:ignore="MergeRootFrame" />
問題的XML格式,當我瀏覽到我的應用程序內該活動的進展左側所示,不居中。我不知道爲什麼會發生這種情況,所以我認爲有人會看到我缺少的東西。謝謝。
編輯:
在我的活動代碼(MyActivity.java)OnCreate事件我有這樣的代碼:
DetailsFragment detailsFragment = new DetailsFragment();
agreementDetailsFragment.setArguments(arguments);
getSupportFragmentManager()
.beginTransaction()
.add(R.id.details_container,
detailsFragment).commit();
,並在我的片段的.java文件中onCreateView我有這樣的代碼
View rootView = null;
/*
* Get root view
*/
LinearLayout wrapper = new LinearLayout(getActivity());
inflater.inflate(R.layout.details_fragment, wrapper, true);
rootView = wrapper;
你究竟如何在片段中使用該佈局(合併的佈局)? – Luksprog
我編輯了我的問題。 – Mediha
您是否嘗試過使用RelativeLayout和android:layout_centerHorizonal =「true」android:layout_centerVertical =「true」 – tophernuts