[英]Constraint layout beta 4 - fragments don't work
注意0:至少嘗試使用此代碼,讓我們知道它是否對您有用。 因為從理論上講這應該起作用,但是它不起作用
注意1:此代碼中沒有錯誤,如果您位於alpha-7以上的任何Constraint布局中,則根本無法使用。 但是,我正在放置logcat。
MainActivity.java:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager mFragmentManager = getSupportFragmentManager();
FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
Fragment fragment = new stupid();
mFragmentTransaction
.add(R.id.main_activity, fragment, "stupid")
.addToBackStack("stupid")
.commit();
}
}
activity_main.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/main_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:clickable="true"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<TextView
android:text="Hi 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="13dp"
tools:layout_editor_absoluteX="18dp"
android:id="@+id/textView" />
</android.support.constraint.ConstraintLayout>
Stupid.java:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
*/
public class stupid extends Fragment {
public stupid() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_stupid, container, false);
}
}
fragment_stupid.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx.stupid">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_blank_fragment"
android:id="@+id/textView2"
tools:layout_constraintTop_creator="1"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="136dp" />
</android.support.constraint.ConstraintLayout>
日志:
12-04 10:28:30.965 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx I/art: Late-enabling -Xcheck:jni
12-04 10:28:31.015 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx I/InstantRun: Instant Run Runtime started. Android package is xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx, real application class is null.
12-04 10:28:31.299 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx W/art: Failed to find OatDexFile for DexFile /data/data/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx/files/instant-run/dex/slice-slice_1-classes.dex ( canonical path /data/data/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx/files/instant-run/dex/slice-slice_1-classes.dex) with checksum 0xe09cbad0 in OatFile /data/data/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx/cache/slice-slice_1-classes.dex
12-04 10:28:31.512 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx I/LoadedApk: No resource references to update in package common
12-04 10:28:31.512 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx I/LoadedApk: No resource references to update in package com.brit.swiftdark
12-04 10:28:31.809 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx W/ResourceType: For resource 0x01030224, entry index(548) is beyond type entryCount(29)
12-04 10:28:31.809 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx W/ResourceType: For resource 0x01030224, entry index(548) is beyond type entryCount(29)
12-04 10:28:31.843 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
12-04 10:28:31.947 12609-12726/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-04 10:28:31.956 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx D/Atlas: Validating map...
12-04 10:28:31.996 12609-12726/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx I/Adreno: QUALCOMM build : 065751b,
Build Date : 04/15/15
OpenGL ES Shader Compiler Version: E031.25.03.07
Local Branch :
Remote Branch : quic/LA.BF64.1.2.1_rb2.9
Remote Branch : NONE
Reconstruct Branch : AU_LINUX_ANDROID_LA.BF64.1.2.1_RB2.05.01.00.081.016 + 065751b + NOTHING
12-04 10:28:32.003 12609-12726/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx I/OpenGLRenderer: Initialized EGL, version 1.4
12-04 10:28:32.011 12609-12726/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx D/OpenGLRenderer: Enabling debug mode 0
12-04 10:28:32.069 12609-12609/xxx.xxxxxxx.xxxxxxxx.xxxxxxxxxxxxx I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@22f2f04f time:200835125
請參考這篇文章的答案...。 ConstraintLayout 1.0.2什么也沒顯示
我知道這既是“此帖子和鏈接的帖子”,也是我的答案。 但我一直在尋找答案將近一年。 我終於發現,出於某種原因,較舊版本的ConstraintLayout將被添加到活動的頂部。 較新版本的ConstraintLayout片段將放在活動的后面。 或至少這就是我的樣子。 這就是為什么我要說的要透明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.