Android Studio Layout is Compressed - java

I have a problem. Everything just looks compressed but my design layout in my IDE is normal as is. What could be the problem?
First pic: The output of the app. Everything is compressed. I have no idea what happened
Second pic: Everything seems normal
This is my XML Code:
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<android.support.constraint.ConstraintLayout
android:layout_width="395dp"
android:layout_height="659dp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<Button
android:id="#+id/btn_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_text"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="131dp" />
<Button
android:id="#+id/btn_txt_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="#android:drawable/ic_dialog_email"
android:text="#string/btn_txt_image"
tools:layout_editor_absoluteX="117dp"
tools:layout_editor_absoluteY="131dp" />
<ImageButton
android:id="#+id/ibtn_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="TODO"
android:onClick="doImageButton"
app:srcCompat="#android:drawable/ic_menu_camera"
tools:layout_editor_absoluteX="237dp"
tools:layout_editor_absoluteY="128dp" />
<CheckBox
android:id="#+id/cbx_fruit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cbx_fruit"
tools:layout_editor_absoluteX="34dp"
tools:layout_editor_absoluteY="221dp" />
<CheckBox
android:id="#+id/cbx_meat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cbx_meat"
tools:layout_editor_absoluteX="135dp"
tools:layout_editor_absoluteY="221dp" />
<RadioGroup
android:id="#+id/rgrp_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="34dp"
tools:layout_editor_absoluteY="283dp">
<RadioButton
android:id="#+id/rbtn_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/rbtn_one" />
<RadioButton
android:id="#+id/rbtn_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/rbtn_two" />
<RadioButton
android:id="#+id/rbtn_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/rbtn_three" />
</RadioGroup>
<RatingBar
android:id="#+id/rbar_star"
android:layout_width="435dp"
android:layout_height="116dp"
tools:layout_editor_absoluteX="-37dp"
tools:layout_editor_absoluteY="454dp" />
<EditText
android:id="#+id/etxt_msg"
android:layout_width="251dp"
android:layout_height="55dp"
android:ems="10"
android:inputType="textPersonName"
android:text="#string/etxt_msg"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="606dp" />
<Button
android:id="#+id/btn_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_toast"
tools:layout_editor_absoluteX="293dp"
tools:layout_editor_absoluteY="612dp" />
<ToggleButton
android:id="#+id/tbtn_power"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tbtn_power"
tools:layout_editor_absoluteX="279dp"
tools:layout_editor_absoluteY="312dp" />
</android.support.constraint.ConstraintLayout>

You need to add constraints to your layout views, heres an example:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/constraintlayout_intro"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:paddingLeft="#dimen/spacing_normal"
android:paddingRight="#dimen/spacing_normal">
<br.com.informant.cegonheira.ui.component.CustomViewPager
android:id="#+id/viewpager_intro"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btn_intro"
android:layout_width="200dp"
android:layout_marginTop="360dp"
android:layout_height="#dimen/spacing_big"
android:background="#drawable/background_rounded_green_gradient_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<me.relex.circleindicator.CircleIndicator
android:id="#+id/circle_indicator_intro"
android:layout_width="match_parent"
android:layout_height="#dimen/spacing_normal"
android:layout_marginTop="460dp"
app:ci_drawable="#drawable/ic_radio_white"
app:ci_drawable_unselected="#drawable/ic_radio_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Notice this in the last view(CircleIndicator):
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
This is what tells where the view is going to be "anchored", otherwise they just "float" like happened to yours.
You can read more about it here: Build a Responsive UI with ConstraintLayout
Congratulations for your first app!

Related

Multiples imagesView with text in a ScrollView

I'm making a soundbox for me and my friends in android studio.
I've got a simple Scroll view, that I filled up with multiple constraintLayout that each contains 2 imageView with each of having a line of text under it.
The problem is that when I run the app, I only see the 2 first layouts, i've no idea what's going on and this is probably not the good way to do it.
What's the best solution here? Here is the xml code :
<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:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="800dp"
android:background="#353535"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/buttonStopAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/red_perso"
android:text="Stop tout"
android:textColor="#000000" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/idTheoGonfle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/theosouffle" />
<ImageView
android:id="#+id/idChuteCJ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/cjchute" />
<TextView
android:id="#+id/textTheoGonfle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="150dp"
android:background="#FFEB3B"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:text="Théo gonfle"
android:textAllCaps="false"
android:textColor="#000000"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/idTheoGonfle" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="150dp"
android:background="#FFEB3B"
android:fontFamily="sans-serif-black"
android:text="TextView"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/idChuteCJ" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout4"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout3"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
<ImageView
android:id="#+id/imageView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/imageView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
<ImageView
android:id="#+id/imageView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>```
look like you are begginer.
<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:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="800dp"
android:background="#353535"
tools:context=".MainActivity">
look like your problem
android:layout_height="800dp"
You set the fix height. Change it to match_parent.
<androidx.constraintlayout.widget.ConstraintLayout. And change root layout to FrameLayout or remove it.

Why aren't my buttons aligning horizontally in Android Studio xml?

I want to change alignment of my button horizontally.
This is my xml code on Android Studio:
<?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/textView"
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/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:onClick="topClick"
android:text="Button"
app:layout_constraintTop_toBottomOf="#+id/textView"
tools:layout_editor_absoluteX="161dp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:onClick="bottomClick"
android:text="Button"
app:layout_constraintTop_toBottomOf="#+id/button"
tools:layout_editor_absoluteX="161dp" />
*It even looks fine on the design panel:
But when I run it on my phone it turns out like this:
It's because you're using tools:layout_editor_absoluteX="161dp" to set the button position in the preview. This won't be applied to the actual app (tool attributes will be removed when the apk is built).
Instead set up the constraints for the buttons as you require, something along the following lines should work,
<?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/textView"
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/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:onClick="topClick"
android:text="Button"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:onClick="bottomClick"
android:text="Button"
app:layout_constraintTop_toBottomOf="#+id/button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
You should have always have all the four constraints defined.
Try using vertical and horizontal bias.
And don't use tools:layout_editor_absoluteX="161dp"
Try this 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/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toStartOf="parent"
app:layout_constraintRight_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_centerHorizontal="true"
android:onClick="topClick"
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.65" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="bottomClick"
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" />
Follow this code
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="317dp" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="#+id/textView6"
app:layout_constraintStart_toStartOf="#+id/textView6"
app:layout_constraintTop_toBottomOf="#+id/textView6" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="#+id/button"
app:layout_constraintStart_toStartOf="#+id/button"
app:layout_constraintTop_toBottomOf="#+id/button" />
<?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/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
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_centerHorizontal="true"
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.65" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>

How to remove extra spaces between the view and the outline border of it in Android?

How can i get rid of these spaces that i marked with red ?
I tried to set padding to zero and nothing changes
<Button
android:id="#+id/req_delete_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="Delete"
app:layout_constraintBottom_toBottomOf="#+id/req_pp"
app:layout_constraintEnd_toStartOf="#+id/req_accept_btn"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="#+id/req_name" />
Note: android:layout_width="0dp" because it has constraints with another button and it expands with it.
Full xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/req_pp"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:background="#drawable/default_pp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/req_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toEndOf="#+id/req_pp"
app:layout_constraintTop_toTopOf="#+id/req_pp" />
<Button
android:id="#+id/req_accept_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="4dp"
android:text="Accept"
app:layout_constraintBottom_toBottomOf="#+id/req_delete_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/req_delete_btn" />
<Button
android:id="#+id/req_delete_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="Delete"
app:layout_constraintBottom_toBottomOf="#+id/req_pp"
app:layout_constraintEnd_toStartOf="#+id/req_accept_btn"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="#+id/req_name" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
It's the shadow around the button in its background drawable. Create your own background and it will disappear. But keep in mind that when you setting android:background="#null" the button loses its touch animation, but it turns out that setting the background to anything at all fixes that border.
Also you can try to use: <Button android:minHeight="0dp" android:minWidth="0dp"
Or in your button's style:
<item name="android:minHeight">0dp</item>
<item name="android:minWidth">0dp</item>
Or try: android:includeFontPadding="false"
I have changed the constrain of the DELETE button to imageview, same as TextView constrain so i can use margin to adjust the space .
now i've putted android:layout_marginStart="14dp" but you can change it to fit your need.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/req_pp"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/default_pp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/req_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="aaa gggg bbb"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toEndOf="#+id/req_pp"
app:layout_constraintTop_toTopOf="#+id/req_pp" />
<Button
android:id="#+id/req_accept_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="16dp"
android:text="Accept"
app:layout_constraintBottom_toBottomOf="#+id/req_delete_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/req_delete_btn" />
<Button
android:id="#+id/req_delete_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginLeft="15dp"
android:layout_marginEnd="4dp"
android:text="Delete"
app:layout_constraintBottom_toBottomOf="#+id/req_pp"
app:layout_constraintEnd_toStartOf="#+id/req_accept_btn"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toEndOf="#+id/req_pp" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>

Android Studio Linear Layout Design issue

I am having an issue with designing Android Studio Layout for App. In linear layout, I want to add first two layouts in the first column horizontally and then in the next column, I wish to add that three buttons in horizontally and finally in the last column want to add Listview. Any help would be highly appreciated. As currently, everything falls into one row.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<james.view.VideoView
android:id="#+id/remoteVideoView"
android:layout_width="120dp"
android:layout_height="90dp"
/>
<james.view.VideoView
android:id="#+id/localVideoView"
android:layout_width="120dp"
android:layout_height="90dp"
/>
<Button
android:id="#+id/startVideoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Call"
/>
<Button
android:id="#+id/stopVideoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End Call"
/>
<Button
android:id="#+id/sendmessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="msg"
/>
<ListView
android:id="#+id/errorList"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</android.support.constraint.ConstraintLayou
This is how I want my layout to be
If you don't understand Constraints. You can use regular LinearLayout.
<?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:padding="10dp"
tools:context=".MainActivity"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="90dp"
>
<james.view.VideoView
android:id="#+id/remoteVideoView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<james.view.VideoView
android:id="#+id/localVideoView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
>
<Button
android:id="#+id/startVideoButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Start Call"/>
<Button
android:id="#+id/stopVideoButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="End Call"/>
<Button
android:id="#+id/sendmessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="msg"/>
</LinearLayout>
<ListView
android:id="#+id/errorList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
>
</ListView>
</LinearLayout>
Quite simple!
Solution:
This is exactly how you want, Just copy paste and your job is done:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<james.view.VideoView
android:id="#+id/remoteVideoView"
android:layout_width="120dp"
android:layout_height="90dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/localVideoView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<james.view.VideoView
android:id="#+id/localVideoView"
android:layout_width="120dp"
android:layout_height="90dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/remoteVideoView"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2">
<Button
android:id="#+id/startVideoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Start Call" />
<Button
android:id="#+id/stopVideoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="End Call" />
<Button
android:id="#+id/sendmessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="msg" />
</LinearLayout>
<ListView
android:id="#+id/errorList"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout3">
</ListView>
</android.support.constraint.ConstraintLayout>
Try it. Hope it helps.
This is a sample xml, similar to your image. Since your code uses constraintLayout I have created the xml using constraintLayout instead of linear layout. I have created this from the design screen and not from the text screen. This is the xml `
<?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"
tools:context=".MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="49dp"
android:layout_marginStart="49dp"
android:layout_marginTop="32dp"
android:text="Button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="67dp"
android:layout_marginRight="67dp"
android:layout_marginTop="32dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="193dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="#+id/button"
app:layout_constraintStart_toStartOf="#+id/button"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:text="Button"
app:layout_constraintBaseline_toBaselineOf="#+id/button3"
app:layout_constraintStart_toEndOf="#+id/button3" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="35dp"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:layout_marginTop="193dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/recyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="19dp"
android:layout_marginEnd="22dp"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:layout_marginStart="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button5" />
</android.support.constraint.ConstraintLayout>
`
Please see if this helps you. This is not exact screen as per your requirements.

Phone unable to display android application as show in Android Studio when debug

After debugging my program and run it on my phone, my phone fail to display exactly what I have design on Android Studio. When using Relative Layout, it display find, now when I switch to Constraint Layout. The problem occur.
Fig 1 is a snapshot of the intended design of my application taken from Android Studio and Fig 2 is the outcome of the application taken from my phone itself
Intended Design (Fig 1)
Outcome image (Fig 2)
XML code
<?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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jasonkym.safstrengthcounter.MainActivity"
android:background="#android:color/background_dark">
<TextView
android:text="No. of blank files:"
android:layout_width="84dp"
android:layout_height="41dp"
android:id="#+id/tvtNoOfBlankFiles"
android:textStyle="normal|bold"
android:textColor="#android:color/holo_orange_light"
tools:layout_editor_absoluteY="160dp"
tools:layout_editor_absoluteX="25dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/etxNoOfBlankFiles"
android:textColor="#android:color/holo_green_dark"
android:text="0"
android:textStyle="normal|bold|italic"
tools:layout_editor_absoluteY="158dp"
tools:layout_editor_absoluteX="117dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvtResults"
android:textSize="24sp"
android:textStyle="normal|bold"
android:textColor="#android:color/holo_blue_bright"
tools:layout_editor_absoluteX="121dp"
tools:layout_editor_absoluteY="415dp" />
<TextView
android:text="No. of people per column:"
android:layout_width="88dp"
android:layout_height="43dp"
android:id="#+id/tvtNoOfPeoplePerRow"
android:textStyle="normal|bold"
android:textColor="#android:color/holo_orange_light"
tools:layout_editor_absoluteX="25dp"
tools:layout_editor_absoluteY="234dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SAF Strength Counter"
android:id="#+id/tvtStrengthCounterLabel"
android:textStyle="normal|bold"
android:textSize="30sp"
android:textColor="#android:color/holo_red_dark"
tools:layout_editor_absoluteX="35dp"
tools:layout_editor_absoluteY="32dp" />
<TextView
android:text="Made by PTE Koh Yi Min Jason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvtMadebyKohYiMinJason"
tools:layout_editor_absoluteY="478dp"
tools:layout_editor_absoluteX="84dp" />
<TextView
android:text="No. of people behind:"
android:layout_width="87dp"
android:layout_height="44dp"
android:id="#+id/tvtNoOfPeopleBehind"
android:textStyle="normal|bold"
android:textColor="#android:color/holo_orange_light"
tools:layout_editor_absoluteX="23dp"
tools:layout_editor_absoluteY="314dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/etxNoOfPeopleBehind"
android:textStyle="normal|bold|italic"
android:text="0"
android:textColor="#android:color/holo_green_dark"
tools:layout_editor_absoluteY="315dp"
tools:layout_editor_absoluteX="118dp" />
<TextView
android:text="No. of column:"
android:layout_width="82dp"
android:layout_height="43dp"
android:id="#+id/tvtNumberOfRows"
android:textStyle="normal|bold"
android:textColor="#android:color/holo_orange_light"
tools:layout_editor_absoluteX="27dp"
tools:layout_editor_absoluteY="91dp" />
<Button
android:text="Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnCalculate"
tools:layout_editor_absoluteY="407dp"
tools:layout_editor_absoluteX="236dp" />
<TextView
android:text="Result:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvtResultsLabel"
android:textSize="24sp"
android:textStyle="normal|bold"
android:textColor="#android:color/holo_orange_light"
tools:layout_editor_absoluteY="415dp"
tools:layout_editor_absoluteX="26dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/etxNoOfRows"
android:textColor="#android:color/holo_green_dark"
android:text="0"
android:textStyle="normal|bold|italic"
tools:layout_editor_absoluteY="91dp"
tools:layout_editor_absoluteX="115dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/etxNoOfPeoplePerRow"
android:textColor="#android:color/holo_green_dark"
android:text="0"
android:textStyle="normal|bold|italic"
tools:layout_editor_absoluteY="234dp"
tools:layout_editor_absoluteX="121dp" />
</android.support.constraint.ConstraintLayout>
I think first you have to take the idea of Relative as well as Constraints layout, then start changing your code. The given link below will help you:
Differences between ConstraintLayout and RelativeLayout
I hope this is help for you.`
<Button
android:id="#+id/btn_search_back"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/color_green"
android:elevation="#dimen/card_elivation"
android:text="#string/back"
android:textColor="#color/color_white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ScrollView
android:id="#+id/layout_show_response"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="#+id/btn_search_back">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/cv_search_for"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_medium"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
card_view:cardBackgroundColor="#color/color_simple_gray">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
style="#style/dialog_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/you_ask_for"
android:textAllCaps="true"
android:textColor="#color/color_black"
android:textStyle="bold"
tools:layout_editor_absoluteY="40dp"
tools:layout_editor_absoluteX="15dp" />
<TextView
android:id="#+id/lbl_ask_for"
style="#style/dialog_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/view_padding_extra_small"
android:text="Ask For"
android:textColor="#color/color_darker_gray"
app:layout_constraintTop_toBottomOf="#+id/textView"
tools:layout_editor_absoluteX="15dp" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_medium"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cv_search_for"
card_view:cardBackgroundColor="#color/color_simple_gray">
<android.support.constraint.ConstraintLayout
android:id="#+id/cl_result"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
style="#style/dialog_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/result"
android:textAllCaps="true"
android:textColor="#color/color_black"
android:textStyle="bold" />
<TextView
android:id="#+id/lbl_reply"
style="#style/dialog_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/view_padding_extra_small"
android:text="Result"
app:layout_constraintTop_toBottomOf="#+id/textView2"
android:textColor="#color/color_darker_gray" />
<LinearLayout
android:id="#+id/layout_img"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
app:layout_constraintTop_toBottomOf="#+id/lbl_reply"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:visibility="gone"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv_show_img"
android:layout_width="#dimen/layout_width_medium"
android:layout_height="#dimen/layout_height_medium"
android:layout_gravity="center"
android:layout_margin="#dimen/view_margin_nano"
android:background="#mipmap/iv_pasted_icon" />
<ImageView
android:id="#+id/iv_show_img_icon"
android:layout_width="#dimen/layout_width_medium"
android:layout_height="#dimen/layout_height_medium"
android:layout_gravity="center"
android:layout_margin="#dimen/view_margin_nano"
android:background="#mipmap/iv_pasted_img" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</ScrollView>
`
I have already solve the problem. You need to add constraint when using ConstraintLayout. It will not display as it shown in the Studio without constraint.
May I asked is there a way which I can design an app just in window visual studio where I am designing a form application just drag and drop and do not have to add any constraint? Is there a layout perhaps that enable me to do that?

Categories

Resources