Я пытаюсь преобразовать свою деятельность во фрагмент, но у меня возникают некоторые проблемы. Макет в HomeFragment является нулевым, поэтому он имеет вид sh ...
My HomeActivity:
public class HomeActivity extends AppCompatActivity {
Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
//the layout on which you are working
ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.homeContainer);
final ConstraintLayout layout2 = (ConstraintLayout) findViewById(R.id.homeContainer);
ViewTreeObserver vto = layout2.getViewTreeObserver();
vto.addOnGlobalLayoutListener (new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
...
My HomeFragment:
public class HomeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_home, container, false);
//the layout on which you are working
ConstraintLayout layout = (ConstraintLayout) getActivity().findViewById(R.id.homeContainer);
final ConstraintLayout layout2 = (ConstraintLayout) getActivity().findViewById(R.id.homeContainer);
ViewTreeObserver vto = layout2.getViewTreeObserver();
vto.addOnGlobalLayoutListener (new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
...
Есть идеи?