My XML code keeps crashing my app, what is wrong with it? - java

I dont know what wrong with it but it's just crashing my app, if you need i will post my java code later cause stack isnt letting me to do it now.When i comment EditTexts it working fine but not as needed so i believe something is wrong with it
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
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">
<EditText
android:id="#+id/A"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="number"/>
<EditText
android:id="#+id/B"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="number"/>
<EditText
android:id="#+id/C"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="number"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/calculate"
android:text="calculate"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/output"
/>
</androidx.core.widget.NestedScrollView>

(Nested)ScrollView can have only one direct child. Basically, ScrollView takes care of scrolling but needs just one element to scroll.
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
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_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/A"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="number"/>
<EditText
android:id="#+id/B"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="number"/>
<EditText
android:id="#+id/C"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="number"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/calculate"
android:text="calculate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/output" />
</LinearLayout >
</androidx.core.widget.NestedScrollView>

Related

How to animate the keyboard?

I have an app and I want to animate the keyboard something like this:
OR is the gif is not working, you can go to this url and get the gif.
Please ignore the first image. I am asking about the second one.
What do I need to do to achieve such an animation? This is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragmentContainer"
android:visibility="gone"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:navigationIcon="#drawable/left"
android:id="#+id/toolbar"
app:popupTheme="#style/Theme.MyApplication.PopupMenu">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
app:civ_border="false"
android:layout_margin="#dimen/_6sdp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="#dimen/_10sdp"
android:gravity="center_vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telegram"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="#dimen/_13sdp"/>
<View
android:layout_width="wrap_content"
android:layout_height="#dimen/_3sdp"/>
<TextView
android:id="#+id/lastSeenTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="last seen 1 minute ago"
android:textSize="#dimen/_9sdp"
android:textColor="#color/white"/>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
app:layout_constraintTop_toBottomOf="#id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/bottomBar"
android:padding="#dimen/_5sdp"
android:background="#E4E4E4"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:reverseLayout="true"
/>
<LinearLayout
android:id="#+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/_40sdp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/_40sdp"
android:orientation="horizontal"
android:background="#color/white">
<ImageView
android:id="#+id/emoji"
android:layout_width="#dimen/_23sdp"
android:layout_height="#dimen/_23sdp"
android:src="#drawable/emoji"
app:tint="#android:color/darker_gray"
android:layout_gravity="center_vertical"
android:layout_marginStart="#dimen/_7sdp"
android:background="?selectableItemBackgroundBorderless"/>
<com.vanniktech.emoji.EmojiEditText
android:id="#+id/message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Message"
android:maxHeight="#dimen/_100sdp"
android:textColorHint="#android:color/darker_gray"
android:paddingVertical="#dimen/_7sdp"
android:paddingHorizontal="#dimen/_7sdp"
android:textColor="#android:color/darker_gray"
tools:text="#string/sample_long_text"
android:backgroundTint="#android:color/transparent"
tools:ignore="HardcodedText" />
<ImageView
android:id="#+id/send"
android:layout_width="#dimen/_23sdp"
android:layout_height="#dimen/_23sdp"
android:src="#drawable/send"
app:tint="#android:color/darker_gray"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="#dimen/_7sdp"
android:background="?selectableItemBackgroundBorderless"/>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

How can I make a layout with multiple fixed views with two of them getting fixed at top with scrolling in Android

<?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">
<RelativeLayout
android:id="#+id/lnrUpper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/lnrUpSide"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/purple_200"
android:orientation="vertical" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/lnrUpSide"
android:background="#color/white">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="225dp"
android:background="#FFF000" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
<LinearLayout
android:id="#+id/fixedHeader"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#color/black"
android:clickable="false"
android:focusable="false">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="FIXED HEADER VIEW"
android:textColor="#color/white"
android:textSize="24sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fixedHeader">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="#F0FE">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FF0E">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#color/black">
</LinearLayout>
</LinearLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="125dp"
android:background="#color/purple_700">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="SECOND FIXED HEADER VIEW"
android:textColor="#color/white"
android:textSize="24sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="1200dp"
android:background="#color/teal_700">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>
</RelativeLayout>
This is my layout xml file and this is how it looks.
This is how my layout look in the first place
When I scroll the layout becomes like this.
Scrolled Layout
However, that is not what I want.
This is the layout I want when I scroll it completely
I was only able to take a screenshot from Android Studio because when I start this at phone the SECOND FIXED HEADER VIEW not got fixed at top. I have tried so many ways but I could not find a solution for this issue. Does anyone know how to make this view ?

XML markup in the Android application

How do I distribute the objects so that the TextView is perfectly in the middle of the parent object, and the ImageButton is on the left. Tried to install for the parent element
android:gravity="center"
, as well as for the TextView itself
android:layout_gravity="center"
, but nothing comes out. I attach the code below.
<?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=".add">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="67dp"
android:orientation="horizontal"
android:gravity="center">
<ImageButton
android:id="#+id/backArrow"
android:layout_width="30dp"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:background="#color/transparent"
android:src="#drawable/back_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/tenor_sans"
android:text="#string/adder"
android:textColor="#2C1E4D"
android:textSize="24sp" />
</LinearLayout>
</RelativeLayout>
Does this help you with your requirement
<?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=".add">
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="67dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/backArrow"
android:layout_width="30dp"
android:layout_height="match_parent"
android:background="#color/colorBlack"
android:scaleType="fitCenter"
android:src="#drawable/back_arrow" />
<TextView
android:layout_gravity="center|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/aclonica"
android:text="#string/adder"
android:textColor="#2C1E4D"
android:textSize="24sp" />
</LinearLayout>
</RelativeLayout>

How would I add rectangular boxes on top of my google maps?

I would like to add 3 boxes on top of the Google Map to hold some text starting from the bottom stacked on top of each other.
Note: <Button> is what I'm using to test out if anything will appear on the google maps. It turns out that nothing appears.
Am I on the right track to achieving what I want? What should I change?
Here's activity_maps.xml:
<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"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="#+id/searchBar"
android:layout_width="289dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:onClick="onSearch"
android:text="SEARCH" />
</LinearLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mancj.example.MapsActivity">
</fragment>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="20dp"
/>
</LinearLayout>
Alright, try this
<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">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mancj.example.MapsActivity">
</fragment>
<LinearLayout
android:background="#android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<EditText
android:hint="Search"
android:id="#+id/searchBar"
android:layout_width="289dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:onClick="onSearch"
android:text="SEARCH" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="#+id/button2"/>
</RelativeLayout>

not a sibling in the same RelativeLayout?

Hello I am starting with Android developing. I am just modifying with Android Studio an open source example.
I have only modified string.xml and some .png files. In the Android simulator it works perfect but when I try to generate the signed Apk file I receive two errors with similar description.
This is one of them (the line is marking with *):
Error:(33) Error: #id/linear_adview is not a sibling in the same
RelativeLayout [Not Sibling]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/rl_content_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background">
<LinearLayout`enter code here`
android:id="#+id/linear_adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.gms.ads.AdView
android:id="#+id/ad_view_editimg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/sticker_recycler_view"
android:layout_below="#id/linear_adview">
<FrameLayout
android:id="#+id/sticker_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/linear_adview">
<ImageView
android:id="#+id/pic_edit_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:scaleType="centerCrop"
android:src="#drawable/background"
/>
<include
layout="#layout/text_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/sticker_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:visibility="visible"
android:layout_above="#+id/linearLayout" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:orientation="horizontal">
<TextView
android:id="#+id/smoke_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:clickable="true"
android:background="#color/black"
android:gravity="center"
android:text="#string/smoke"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/text_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:clickable="true"
android:gravity="center"
android:text="#string/text"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/share_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:clickable="true"
android:text="#string/share"
android:textColor="#color/white"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>`
`
FrameLayout with android:id="#+id/sticker_framelayout" isn't a direct sibling of LinearLayout with android:id="#+id/linear_adview" and that's why you can't use android:layout_below="#id/linear_adview" in it. Actually you can merge RelativeLayout and FrameLayout into one view:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/sticker_recycler_view"
android:layout_below="#id/linear_adview">
<FrameLayout
android:id="#+id/sticker_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/linear_adview">
(...)
</FrameLayout>
to
<FrameLayout
android:id="#+id/sticker_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/sticker_recycler_view"
android:layout_below="#id/linear_adview">
(...)
</FrameLayout>

Categories

Resources