I am trying to develop a simple calculator which has only add and subtraction functions using Andriod Studion. But when I run it all the elements are overlapping. I have attached a screenshot to get more clear idea about my problem. I really appreciate if anyone can tell me why I got this and how to fixed it.
screenshot
Actually you are not using the layouts properly. I will suggest you
to learn the layouts properly then you will not face such issues.
Thank you.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="10dp"
tools:context=".ui.activities.MainActivity">
<TextView
android:id="#+id/text1"
android:layout_width="250dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="#string/first_number" />
<EditText
android:id="#+id/editText1"
android:layout_width="250dp"
app:layout_constraintTop_toBottomOf="#id/text1"
app:layout_constraintStart_toStartOf="parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/text2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="#string/second_number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText1"
/>
<EditText
android:id="#+id/editText2"
android:layout_width="250dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/text2"
android:hint="Enter First Number" />
<TextView
android:id="#+id/text3"
android:layout_width="250dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText2"
android:text="#string/answer" />
<EditText
android:id="#+id/editText3"
android:layout_width="250dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/text3"
android:hint="Enter First Number" />
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"
android:layout_weight="0.5"
android:layout_marginTop="80dp"
app:layout_constraintTop_toBottomOf="#id/editText3"
app:layout_constraintStart_toStartOf="parent"
android:background="#color/colorPrimary"
/>
<Button
android:id="#+id/btn2"
android:layout_weight="0.5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/btn1"
android:background="#color/colorPrimary"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Related
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.
I have a problem with layout in my app that I am writing. I want to make some domestic changes like buttons to be in one column and they should be on right hand side. Additionally EditText with Buttons should be around middle of the screen ( I attach screenshot of how it looks for now). After reading few of similar problems the main idea was to modify textView1 on layout_width="fill_parent", but that doesnt make any difference. Most of changes that I am trying doesnt seems to have any effect, do you know why ?Current Layout
I am also giving the adapter view layout xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<TextView
android:gravity="center"
android:text="TextView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/textView1"
android:textSize="18sp"
android:layout_weight="66.6"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="33.3">
<Button
android:id="#+id/removeBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_btn_remove"
android:backgroundTint="#color/black" />
<EditText
android:id="#+id/itemAmount"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:inputType="number"
android:minEms="1"
android:text="1"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="#android:color/black"
android:textSize="20sp" />
<Button
android:id="#+id/addBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_btn_add"
android:backgroundTint="#color/black" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_marginLeft="60dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:clickable="true"
app:fabCustomSize="40dp"
app:srcCompat="?android:attr/textCheckMarkInverse" />
</LinearLayout>
</LinearLayout>
I've been working on my app and i've come across an issue where in the preview, whenever i place text below the button for example the "roomservice" button it doesnt show it on the emulator when running but it does in the preview. What am i doing wrong here?
This is my xml code as its the only coding part i've been working on, i've also added android:layout_below="#id/roomservice"/> in the textview but it still did not 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"
android:background="#drawable/gradient"
tools:context=".MainMenu">
<ImageButton
android:id="#+id/roomservice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="26dp"
android:layout_marginLeft="26dp"
android:layout_marginTop="95dp"
app:srcCompat="#drawable/ic_room_service_black_24dp" />
<TextView
android:id="#+id/textView"
android:layout_width="100dp"
android:layout_height="37dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="34dp"
android:layout_marginLeft="34dp"
android:layout_marginBottom="497dp"
android:text="Room Service"
android:textColor="#F8F1F5F4"
android:textFontWeight="14"
android:layout_below="#id/roomservice"/>
<ImageButton
android:id="#+id/transportation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginStart="237dp"
android:layout_marginLeft="237dp"
android:layout_marginTop="238dp"
app:srcCompat="#drawable/ic_taxi" />
<ImageButton
android:id="#+id/foodservice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="239dp"
android:layout_marginLeft="239dp"
android:layout_marginTop="92dp"
app:srcCompat="#drawable/ic_restaurant" />
<ImageButton
android:id="#+id/maintenance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="234dp"
app:srcCompat="#drawable/ic_maintenance" />
<ImageButton
android:id="#+id/checkout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="26dp"
android:layout_marginLeft="26dp"
android:layout_marginTop="368dp"
app:srcCompat="#drawable/ic_checkout" />
<ImageButton
android:id="#+id/baggagecollection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="234dp"
android:layout_marginLeft="234dp"
android:layout_marginTop="373dp"
app:srcCompat="#drawable/ic_bag" />
Try removing the line:
android:layout_alignParentStart="true"
from the markup for the textview. This parameter, according to the documentation, will "make the start edge of this view match the start edge of the parent". Both the TextView and The first ImageButton have the same parent (the layout), so your views could be generating on top of each other.
The 'start' position is also dependent on on the locale setting of the device. This might explain why the layout is displaying differently across devices.
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.
I managed to make bold text by adding android:textStyle="bold" to all sections of my xml file i.e EditText, Button, TextView, etc. But is there a way to make it global so that it affects the entire application? Or do I have to always specify the fields I want bold? I hope this makes sense. Thank you.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b5b3b3"
android:textStyle="bold"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textStyle="bold"
android:hint="Enter Text Here" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Show Items" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Items will display here"
android:color="#FFF8AA"
android:textStyle="bold"
android:orientation="vertical" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="SaveText" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Number of Items in Array" />
</LinearLayout>
If your application is using PhoneGap, you can specify the font weight in a .css file. Just attach the css to all your pages with the following code.
body
{
font-weight:bold;
}
If you're not using PhoneGap, I'm afraid I can't help you.