我切换到约束布局的新更新,这就是我得到的,只是一个白屏
想也许我在我的片段中做错了什么,但不,它没有显示任何错误。所以我试图检查布局,这就是我得到的
它为文本编辑器创造了空间,但它不绘制任何东西。这是我的 XML
<android.support.constraint.ConstraintLayout 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/fragment_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Plum"
android:clickable="true"
tools:context=".ui.LoginFragment">
<EditText
android:id="@+id/login_username"
android:layout_width="300dp"
android:layout_height="50dp"
android:gravity="center"
android:hint="@string/Username_or_Email"
android:inputType="textNoSuggestions|textEmailAddress"
android:lines="1"
android:linksClickable="false"
app:layout_constraintBottom_toTopOf="@+id/login_password"
app:layout_constraintRight_toRightOf="@+id/login_password" />
<EditText
android:id="@+id/login_password"
android:layout_width="300dp"
android:layout_height="50dp"
android:gravity="center"
android:hint="@string/password"
android:inputType="textPassword"
android:lines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/login_login"
style="@style/Base.Widget.AppCompat.Button.Colored.login"
android:layout_width="150dp"
android:layout_height="50dp"
android:text="@string/login"
app:layout_constraintLeft_toLeftOf="@+id/login_password"
app:layout_constraintRight_toRightOf="@+id/login_password"
app:layout_constraintTop_toBottomOf="@+id/login_password" />
<Button
android:id="@+id/login_singup"
style="@style/Base.Widget.AppCompat.Button.Colored.signup"
android:layout_width="0dp"
android:layout_height="50dp"
android:background="@color/Indigo"
android:clickable="true"
android:gravity="center"
android:lines="1"
android:text="@string/singup"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
我不确定是什么导致了问题。它与 alpha 7 完美配合:/有什么帮助吗?
编辑:
片段是这样创建的:
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
switch (fragmentName) {
case "LoginFragment":
Log.d(KEY_CLASS_NAME, "createFragment-LoginFragment");
fragment = new LoginFragment();
mFragmentTransaction.setCustomAnimations(
R.anim.icon_anim_fade_in,
R.anim.icon_anim_fade_out,
R.anim.icon_anim_fade_in,
R.anim.icon_anim_fade_out)
.add(R.id.dispatcher_container, fragment, SPKey.KEY_LOGIN_FRAGMENT)
.addToBackStack(SPKey.KEY_LOGIN_FRAGMENT)
.commit();
break;
OnCreateView() 是在 LoginFragment 内部实现的:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mView = inflater.inflate(R.layout.fragment_login, container, false);
if (mView != null) {
Log.d("LoginFragment", "creating ver");
mUsername = (EditText) mView.findViewById(R.id.login_username);
mPassword = (EditText) mView.findViewById(R.id.login_password);
mLogin = (Button) mView.findViewById(R.id.login_login);
mSignUp = (Button) mView.findViewById(R.id.login_singup);
mLogin.setOnClickListener(this);
mSignUp.setOnClickListener(this);
Log.d("LoginFragment", "done creating ver");
} else {
Log.d("LoginFragment", "mView is empty");
}
return mView;
}
此外,我刚刚发现 Android Studio 2.2.1 中的 SDK 管理器在“~\Android\sdk\extras”中下载“m2repository”,但如果您使用独立 SDK 管理器,它会将“m2repository”放在“~\Android\ sdk\extras\android"。我不知道这是否重要,但这就是约束布局文件夹所在的位置。