Design Layout is missing after adding FragmentContainerView - android-studio

My design layout in android studio is missing after i add FragmentContainerView. Its worrking fine before, but after a while this happen. How to fix it?
here is my xml code :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:background="#color/blue"
tools:context=".MainActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_marginStart="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/img" />
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragmentContainerView"
android:name="com.DStudio.Finjer.MainFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="15dp"
android:background="#drawable/rectangle_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<com.google.android.gms.ads.AdView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

In the error panel there must be an option to "suppress the warning for this session". Once you do that your layout will show.

Related

Android Studio, Constraint Widget does not work

In my Android Studio my constraint widget does not work. Whenever I put in a value for the top margin the design doesn't change. for example, in the image you will see 84 in the constraint widget I want to change it to 20 but when I do nothing happens. How do I make this work?
Here is the xml code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<TextView
android:id="#+id/txtVw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/ALButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onBtnClick"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edtxtName" />
<EditText
android:id="#+id/edtxtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="84dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/txtVw" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is the design image:
I have a similar problem here. looks like a bug in your version of Android Studio. Try using Android Studio Arctic Fox|2020.3.1 Patch 2

Linear Layout and children not visible

Hi sorry I am having difficulty in getting my layout to been seen when I run the application
I don't see anything when I run my application
here is my XML code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<LinearLayout
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/edtName"
android:layout_width="match_parent"
android:layout_height="44dp"
android:text="Name" />
<ScrollView
android:id="#+id/scrlText"
android:layout_width="match_parent"
android:fillViewport="true"
android:isScrollContainer="true"
android:layout_height="638dp">
<LinearLayout
android:id="#+id/lltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<LinearLayout
android:id="#+id/hllsend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/edtInput"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="#+id/btnSend"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
How do I make my items visible when running the application?
In your simple layout code, there are many problems. For example:
1.
android:layout_width="409dp"
android:layout_height="729dp"
such android screen size is hard to get. And in Android layout principal, you'd better use relative layout rather than such hard code size. Here you can replace it with match_parent or wrap_content.
In the same way.
android:layout_height="638dp"
totally over screen height ,make no space for hllsend to show.
I suggest you learn some android layout principal before write android app.
It's not a good practice to add LinearLayout in ConstraintLayout and I think it's the issue with your code you just need to make you LinearLayout as a parent and remove your ConstraintLayout.
NOTE: please do necessary adjustment.
Please check quick example for your code I didn't run this.
<LinearLayout 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=".MainActivity">
<LinearLayout
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/edtName"
android:layout_width="match_parent"
android:layout_height="44dp"
android:text="Name" />
<ScrollView
android:id="#+id/scrlText"
android:layout_width="match_parent"
android:fillViewport="true"
android:isScrollContainer="true"
android:layout_height="638dp">
<LinearLayout
android:id="#+id/lltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<LinearLayout
android:id="#+id/hllsend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="#+id/edtInput"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="#+id/btnSend"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
put all your xml codes in LinearLayout and remove ConstraintLayout . thats may helps.

Why my android emulator isn't showing buttons?

I made this simple activity in my Android Studio. But when I run this on my Android emulator it doesn't shows the buttons that I added to my activity
<RelativeLayout 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=".MainActivity">
<TextView
android:layout_width="101dp"
android:layout_height="101dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="151dp"
android:layout_marginTop="340dp"
android:layout_marginEnd="159dp"
android:layout_marginBottom="355dp"
android:text="This is app"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btn1"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="153dp"
android:layout_marginTop="392dp"
android:layout_marginEnd="152dp"
android:layout_marginBottom="291dp"
android:text="````
This code should work:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true">
<TextView
android:layout_width="101dp"
android:layout_height="101dp"
android:text="This is app"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"/>
<Button
android:id="#+id/btn1"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="Click Me"/>
</LinearLayout>
</RelativeLayout>

Displaying a button inside a video view

How will I display a button inside a video view with the android studio? The button seems to be there but not visible.
<RelativeLayout>
<VideoView
android:id="#+id/vV"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"/>
<Button
android:id="#+id/btn"
android:text="btn"/>
</RelativeLayout>
I want the button to appear visible in the video view. The button is clickable but not visible
Use Constrain layout by adding
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
to your gradle
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#color/colorbackground">
<VideoView
android:id="#+id/videoView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.8" />
</android.support.constraint.ConstraintLayout>
you can simply use this inside button:
android:background="#00DAEDCC"
this will make your button transparent. I think, it will help you.

Android Material Design- Elevation shadow not working for nested inner layouts

I am writing a code with a few nested layouts. As I have used material design I also wanted to set elevation. Though elevation was working fine with the elements of outermost layout, the contents of the inner LinearLayout (nested inside a CoordinatorLayout) is not casting shadows despite setting elevation.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/white"
tools:context="com.joblesscoders.aditya.todolist.HomeActivity">
<TextView
android:layout_width="match_parent"
android:id="#+id/count"
android:text="Main Activity"
android:textSize="20dp"
android:elevation="5dp"
android:textColor="#color/white"
android:gravity="center_vertical"
android:background="#color/colorPrimary"
android:layout_height="50dp" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/cly"
android:background="#color/white"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sv"
android:background="#color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lly"
android:background="#color/white"
android:orientation="vertical">
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<!-- More TextViews to suit purpose -->
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="#drawable/ic_add2"
app:rippleColor="#color/white"
android:id="#+id/fab"
android:layout_gravity="bottom|end"
/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
This code in android studio designer view produces the expected result i.e.
the TextViews displaying "Task here" have required shadows, but as soon I run it on a android 6.O custom device, the page becomes:
I would be thankful if anybody corrects me or advices on the dos and don'ts. I am extremely new to android programming, and this is my first code. So please bear with me if I have made any really very silly mistake.

Resources