我已經閱讀了許多關於同一問題的問題,但沒有一個答案解決了我的問題。片段在佈局內不可見但工作正常
這是我活動的佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
tools:host="clyky.cartracker.activities.RegistrationActivity"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginStart="@dimen/container_default_left_margin"
android:layout_marginEnd="@dimen/container_default_right_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_id_card"/>
</FrameLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:id="@+id/txtUsername"
android:hint="Username"
android:layout_marginBottom="@dimen/edit_text_bottom_margin"
android:padding="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:id="@+id/txtPassword"
android:hint="Password"
android:layout_marginBottom="@dimen/edit_text_bottom_margin"
android:padding="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:id="@+id/txtConfirmPassword"
android:hint="Confirm password"
android:layout_marginBottom="@dimen/edit_text_bottom_margin"
android:padding="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:id="@+id/txtName"
android:hint="Name"
android:layout_marginBottom="@dimen/edit_text_bottom_margin"
android:padding="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:id="@+id/txtSurname"
android:hint="Surname"
android:layout_marginBottom="@dimen/edit_text_bottom_margin"
android:padding="5dp"/>
<Button
android:text="Registrati"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnSignUp"
android:layout_margin="15dp"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/registrationContainer">
</FrameLayout>
</LinearLayout>
我的片段最後FrameLayout
registrationContainer
內補充說:
LoadingRegistrationFragment f = LoadingRegistrationFragment.newInstance(args);
Utilities.addFragment(R.id.registrationContainer, f, null, getSupportFragmentManager());
這是我addFragment
方法:
public static void addFragment(int containerID, Fragment toAdd, @Nullable String tag, FragmentManager manager)
{
FragmentTransaction trans = manager.beginTransaction();
trans.add(containerID, toAdd, tag);
trans.commit();
}
而且這是我的LoadingRegistrationFragment
的onCreateView
:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Bundle args = getArguments();
username = args.get("username").toString();
encryptedPassword = args.get("password").toString();
name = args.get("name").toString();
surname = args.get("surname").toString();
listener = (RegistrationListener) getActivity();
View v = inflater.inflate(com.devspark.progressfragment.R.layout.fragment_progress, container, false);
sendRequest();
return v;
}
我的片段工作正常,它只是看不見,我找不出原因。 我用調試器檢查過,如果v
在我的onCreateView
是null
但不是,它已經得到了一個值。 我也嘗試將我的活動佈局封裝在ScrollView
中,以查看片段是否顯示得太低,但仍然不可見。
爲了調試目的,只隱藏所有對象並放置僅framelayout來測試片段是否被加載。增加重量到framelayout。如果可能的話,你可以用pic更新屏幕的加載方式。 –
請繼續並分享您的片段XML –
@RedM它是一個外部庫,我沒有片段XML,但它只是一個循環不確定的進度條。這是圖書館:https://github.com/johnkil/Android-ProgressFragment – Clyky