I am using Floating icon in my Activity and I also want to use Navigation Drawer in this Activity but when I use it, my background layout is not working. And when I place it in my code My icon is showing on the menu list. Please help what should I do.I am using constraint layout but it is not showing here...
<?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:floatingMenuActionButton="http://schemas.android.com/tools"
android:id="#+id/pai"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="#FFFFFF">
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
app:menu="#menu/navigation_menu"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
android:id="#+id/nv">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<android.support.constraint.Guideline
android:id="#+id/gl_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="1.0"/>
<android.support.constraint.Guideline
android:id="#+id/gl_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="1.0"/>
<rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton
android:id="#+id/fab_1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="52dp"
android:scaleType="centerInside"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
floatingMenuActionButton:dispositionEndAngle="360"
floatingMenuActionButton:dispositionStartAngle="0"
floatingMenuActionButton:subActionButtonRadius="200"
android:layout_marginBottom="8dp"
android:background="#drawable/poultary"
app:layout_constraintBottom_toTopOf="#+id/gl_1">
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_2"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_3"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_4"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_5"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_6"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_7"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_8"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
</rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton>
-->
you should make your main layout as drawer and then include constraint layout in it
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/your_constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
app:menu="#menu/navigation_menu"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
android:id="#+id/nv">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
your_constraint_layout
<?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:floatingMenuActionButton="http://schemas.android.com/tools"
android:id="#+id/pai"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="#FFFFFF">
<android.support.constraint.Guideline
android:id="#+id/gl_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="1.0" />
<android.support.constraint.Guideline
android:id="#+id/gl_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="1.0" />
<rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton
android:id="#+id/fab_1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:background="#drawable/poultary"
android:scaleType="centerInside"
app:layout_constraintBottom_toTopOf="#+id/gl_1"
app:layout_constraintRight_toRightOf="parent"
floatingMenuActionButton:dispositionEndAngle="360"
floatingMenuActionButton:dispositionStartAngle="0"
floatingMenuActionButton:subActionButtonRadius="200">
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_2"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_3"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_4"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_5"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_6"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_7"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
<rjsv.floatingmenu.floatingmenubutton.subbutton.FloatingSubButton
android:id="#+id/fab_1_sub_fab_left_8"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/poultary" />
</rjsv.floatingmenu.floatingmenubutton.FloatingMenuButton>
Related
I tried to stick counter to nameText while counter should not exceed the container from the right side.
I want to only use the xml and no programmatically change it.
I played with the layout.xml
code example:
<?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:id="#+id/wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#99776633"
tools:ignore="MissingDefaultResource">
<TextView
android:id="#+id/nameText"
android:layout_width="0dp"
android:layout_height="0dp"
android:ellipsize="end"
android:foreground="#66ff0000"
android:lines="1"
android:textSize="17dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap"
tools:text="James BondJameames " />
<View
android:id="#+id/seperator"
android:layout_width="1dp"
android:layout_height="1dp"
app:layout_constraintLeft_toRightOf="#id/nameText"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/counter"
android:layout_width="0dp"
android:layout_height="0dp"
android:foreground="#9900fff0"
android:lines="1"
android:text="(47)"
android:textSize="17dp"
app:layout_constraintLeft_toRightOf="#id/seperator"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap" />
</androidx.constraintlayout.widget.ConstraintLayout>
The results:
With short text:
With long text:
The expected result should be something like that:
Try placing the three views into a horizontal chain while shifting the horizontal bias of nameText to zero.
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#99776633"
tools:ignore="MissingDefaultResource">
<TextView
android:id="#+id/nameText"
android:layout_width="0dp"
android:layout_height="0dp"
android:ellipsize="end"
android:foreground="#66ff0000"
android:lines="1"
android:textSize="17dp"
app:layout_constraintEnd_toStartOf="#+id/counter"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap"
tools:text="Short text" />
<View
android:id="#+id/seperator"
android:layout_width="1dp"
android:layout_height="1dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/counter"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/counter"
android:layout_width="0dp"
android:layout_height="0dp"
android:foreground="#9900fff0"
android:lines="1"
android:text="(47)"
android:textSize="17dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="#+id/seperator"
app:layout_constraintStart_toEndOf="#+id/nameText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap" />
</androidx.constraintlayout.widget.ConstraintLayout>
See the documentation on chains.
<?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:id="#+id/wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#99776633"
tools:ignore="MissingDefaultResource">
<TextView
android:id="#+id/nameText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:foreground="#66ff0000"
android:lines="1"
android:textSize="17dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#id/seperator"
tools:text="James BondJameames " />
<View
android:id="#+id/seperator"
android:layout_width="1dp"
android:layout_height="1dp"
app:layout_constraintEnd_toStartOf="#id/counter"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/counter"
android:layout_width="0dp"
android:layout_height="0dp"
android:foreground="#9900fff0"
android:lines="1"
android:text="(47)"
android:textSize="17dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have this scenario in an android page:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#drawable/border">
<RelativeLayout
android:id="#+id/lbltvFirstContainer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="90" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lbltvFirstText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:visibility="visible"
android:layout_gravity="left"
android:textSize="19dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvSecondText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvFirstText"
android:textColor="#color/green"
android:textSize="19dp"
android:textStyle="bold" />
<com.google.android.flexbox.FlexboxLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:flexDirection="row"
app:justifyContent="flex_end"
app:flexWrap="wrap"
app:layout_flexBasisPercent="50%"
app:alignItems="flex_start"
app:alignContent="flex_start"
app:showDividerVertical="middle"
app:dividerDrawable="#drawable/divider_flexbox">
<com.google.android.material.button.MaterialButton
android:id="#+id/btnButton"
android:background="#android:color/transparent"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginTop="-5dp"
app:icon="#drawable/btnButton"
app:iconTint="#null" />
<ImageView
android:id="#+id/first_icon"
android:src="#drawable/grey_24dp"
android:background="#android:color/transparent"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_weight="0.5"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:layout_alignParentRight="true"/>
</com.google.android.flexbox.FlexboxLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/elements_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lblThirdImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="#drawable/icon_image"
android:layout_marginLeft="4dp"
android:layout_gravity="start" />
<TextView
android:id="#+id/tvThirdText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:layout_toRightOf="#+id/lblThirdImage"
android:gravity="start"
android:textSize="18dp" />
</RelativeLayout>
<com.google.android.flexbox.FlexboxLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:flexWrap="wrap"
app:alignItems="stretch"
app:alignContent="stretch"
app:showDividerVertical="middle"
app:dividerDrawable="#drawable/divider" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lblFourImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="#drawable/four_image"
android:visibility="visible"
android:layout_marginLeft="4dp"
android:layout_gravity="start" />
<TextView
android:id="#+id/tvFourText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvFourImage"
android:gravity="start"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lbltvFiveImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:visibility="visible"
android:layout_marginLeft="4dp"
android:layout_gravity="start"
android:src="#drawable/five_image" />
<TextView
android:id="#+id/tvFiveText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvFiveImage"
android:gravity="start"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lbltvSixImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:visibility="visible"
android:layout_marginLeft="4dp"
android:layout_gravity="start"
android:src="#drawable/six_image" />
<TextView
android:id="#+id/tvSixText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvSixImage"
android:gravity="start"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lbltvSevenImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="#drawable/seven_image"
android:visibility="visible"
android:layout_marginLeft="4dp"
android:layout_gravity="start" />
<TextView
android:id="#+id/tvSevenImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvSevenImage"
android:gravity="start"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tvEightImage"
android:src="#drawable/eigth_image"
android:background="#android:color/transparent"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginRight="4dp"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tvNineImage"
android:src="#drawable/nine_image"
android:background="#android:color/transparent"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"/>
<com.google.android.material.button.MaterialButton
android:id="#+id/lblTenImage"
android:background="#android:color/transparent"
android:layout_width="42dp"
android:layout_height="42dp"
app:icon="#drawable/ten_image"
app:iconTint="#null" />
</LinearLayout>
</com.google.android.flexbox.FlexboxLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/lbltvSecondContainer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="10">
</RelativeLayout>
</LinearLayout>
And I am trying to have two containers side by side, lbltvFirstContainer and lbltvSecondContainer, where I would set width by percentage so in the second container I can put just a ">" like a button to go to another page so after searching I found somewhere to use those app:layout_constraintWidth_default="percent" and app:layout_constraintWidth_percent="10" but looks like that doesn't work.... do you have a direction to make those two main containers with percentage width? Thanks in advance!
Cheers
Edit:
after #Cheticamp 's suggest I changed as :
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#drawable/border">
<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">
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/left_guideline"
app:layout_constraintGuide_percent=".80"
android:orientation="horizontal" />
<RelativeLayout
android:id="#+id/left_container"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintEnd_toStartOf="#+id/left_guideline"
app:layout_constraintStart_toStartOf="parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lbltvFirstText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:visibility="visible"
android:layout_gravity="left"
android:textSize="19dp"
android:textStyle="bold"
android:text="Matricola:" />
<TextView
android:id="#+id/tvSecondText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvFirstText"
android:textColor="#color/area_frg"
android:textSize="19dp"
android:textStyle="bold" />
<com.google.android.flexbox.FlexboxLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:flexDirection="row"
app:justifyContent="flex_end"
app:flexWrap="wrap"
app:layout_flexBasisPercent="50%"
app:alignItems="flex_start"
app:alignContent="flex_start"
app:showDividerVertical="middle"
app:dividerDrawable="#drawable/divider_flexbox">
<com.google.android.material.button.MaterialButton
android:id="#+id/btnButton"
android:background="#android:color/transparent"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginTop="-5dp"
app:icon="#drawable/btnButton"
app:iconTint="#null" />
<ImageView
android:id="#+id/first_icon"
android:src="#drawable/grey_24dp"
android:background="#android:color/transparent"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_weight="0.5"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:layout_alignParentRight="true"/>
</com.google.android.flexbox.FlexboxLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lblThirdImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="#drawable/wifi"
android:layout_marginLeft="4dp"
android:layout_gravity="start" />
<TextView
android:id="#+id/tvThirdText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:layout_toRightOf="#+id/lblThirdImage"
android:gravity="start"
android:textSize="18dp" />
</RelativeLayout>
<com.google.android.flexbox.FlexboxLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:flexWrap="wrap"
app:alignItems="stretch"
app:alignContent="stretch"
app:showDividerVertical="middle"
app:dividerDrawable="#drawable/divider" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lblFourImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="#drawable/thermo"
android:visibility="visible"
android:layout_marginLeft="4dp"
android:layout_gravity="start" />
<TextView
android:id="#+id/tvFourText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lblFourImage"
android:gravity="start"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lbltvFiveImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:visibility="visible"
android:layout_marginLeft="4dp"
android:layout_gravity="start"
android:src="#drawable/full_batt" />
<TextView
android:id="#+id/tvFiveText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvFiveImage"
android:gravity="start"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lbltvSixImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:visibility="visible"
android:layout_marginLeft="4dp"
android:layout_gravity="start"
android:src="#drawable/power" />
<TextView
android:id="#+id/tvSixText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvSixImage"
android:gravity="start"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lbltvSevenImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="#drawable/gsm"
android:visibility="visible"
android:layout_marginLeft="4dp"
android:layout_gravity="start" />
<TextView
android:id="#+id/tvSevenText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="4dp"
android:visibility="visible"
android:layout_toRightOf="#+id/lbltvSevenImage"
android:gravity="start"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tvEightImage"
android:src="#drawable/eight_image"
android:background="#android:color/transparent"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginRight="4dp"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tvNineImage"
android:src="#drawable/nine_image"
android:background="#android:color/transparent"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"/>
<com.google.android.material.button.MaterialButton
android:id="#+id/lblTenImage"
android:background="#android:color/transparent"
android:layout_width="42dp"
android:layout_height="42dp"
app:icon="#drawable/play"
app:iconTint="#null" />
</LinearLayout>
</com.google.android.flexbox.FlexboxLayout>
</RelativeLayout>
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/right_guideline"
app:layout_constraintGuide_percent=".20"
android:orientation="horizontal" />
<RelativeLayout
android:id="#+id/right_container"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintEnd_toStartOf="#+id/right_guideline"
app:layout_constraintStart_toStartOf="parent">
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
using those ConstraintLayout but seems it keeps returning this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mytestapp, PID: 32175
java.lang.AssertionError: LEFT
at androidx.constraintlayout.solver.widgets.Guideline.getAnchor(Guideline.java:147)
at androidx.constraintlayout.solver.widgets.ConstraintWidget.immediateConnect(ConstraintWidget.java:1620)
at androidx.constraintlayout.widget.ConstraintLayout.applyConstraintsFromLayoutParams(ConstraintLayout.java:1359)
at androidx.constraintlayout.widget.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:1253)
at androidx.constraintlayout.widget.ConstraintLayout.updateHierarchy(ConstraintLayout.java:1149)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1685)
at android.view.View.measure(View.java:25532)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25532)
at android.widget.ListView.measureScrapChild(ListView.java:1350)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1419)
at android.widget.ListView.onMeasure(ListView.java:1323)
at android.view.View.measure(View.java:25532)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:25532)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:25532)
at androidx.recyclerview.widget.RecyclerView$LayoutManager.measureChildWithMargins(RecyclerView.java:9384)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1653)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
at android.view.View.layout(View.java:22900)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at androidx.viewpager2.widget.ViewPager2.onLayout(ViewPager2.java:527)
at android.view.View.layout(View.java:22900)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:148)
at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:43)
at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:2003)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:918)
at android.view.View.layout(View.java:22900)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:22900)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
at android.view.View.layout(View.java:22900)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:22900)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
E/AndroidRuntime: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
at android.view.View.layout(View.java:22900)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:831)
at android.view.View.layout(View.java:22900)
at android.view.ViewGroup.layout(ViewGroup.java:6389)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3619)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3087)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2060)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8430)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
at android.view.Choreographer.doCallbacks(Choreographer.java:796)
at android.view.Choreographer.doFrame(Choreographer.java:731)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7886)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:970)
so I re-checked what I typed in XML and seems it looks ok but maybe shall I have forgot or mistaken something ?
Thanks!
Cheers!
Edit 2 :
Hello #Cheticamp , following your suggest I started from scratch to create a ConstraintLayout with two guidelines dimensioned by percent as follow:
<?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">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/test_left_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.50" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/test_right_guideline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.20"
app:layout_constraintLeft_toEndOf="#id/test_left_guideline" />
</androidx.constraintlayout.widget.ConstraintLayout>
so it's supposed to see in Design those two guidelines side by side since I put app:layout_constraintLeft_toEndOf="#id/test_left_guideline" so after I could put two RelativeLayouts as containers following those guidelines but it looks like both guidelines starts from the left side of the parent window... which attribute I should set to make those two guidelines side by side? Thanks in advance! Cheers
I created layout with floating action button. There is one floating action button (called filter) by which i show up two other FABs.
Issue is about space between FABs. Gap is showing more in API level 18 and below.
Layout is working good in API level 19 and above but it is not showing properly in below 19, there is too much gap between floating action button, not sure what is issue here. Please let me know if i need spacial handling for 18 and below.
enter code here
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bottom_bar_color"
android:paddingTop="#dimen/activity_vertical_margin">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/pull_to_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.stylzq.widget.StylzQRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/images_data_list_frag_rv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/go_to_top_fab"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="130dp"
android:layout_marginRight="15dp"
android:clickable="false"
android:src="#drawable/go_to_top"
android:visibility="gone"
app:backgroundTint="#color/colorPrimary"
app:borderWidth="0dp"
app:elevation="6dp"
app:layout_anchorGravity="bottom|right"
app:pressedTranslationZ="12dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="190dp"
android:gravity="end"
android:orientation="vertical">
<LinearLayout
android:id="#+id/ll_home_lyt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_6"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/fab_text_background"
android:padding="#dimen/dimen_3"
android:text=" Home "
android:textColor="#color/white"
android:textSize="16sp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_home_api"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginTop="#dimen/dimen_6"
android:layout_marginRight="16dp"
android:src="#drawable/ic_home"
app:backgroundTint="#color/colorPrimary"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorPrimaryLight" />
</LinearLayout>
<LinearLayout
android:id="#+id/celebs_lyt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_6"
android:visibility="gone">
<TextView
android:id="#+id/celeb_TV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/fab_text_background"
android:padding="#dimen/dimen_3"
android:text=" Celebrity "
android:textColor="#color/white"
android:textSize="16sp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/celebs_api_fab"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginRight="16dp"
android:src="#drawable/ic_celeb"
app:backgroundTint="#color/colorPrimary"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorPrimaryLight" />
</LinearLayout>
<LinearLayout
android:id="#+id/popular_lyt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_6"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/fab_text_background"
android:padding="#dimen/dimen_3"
android:text=" Popular "
android:textColor="#color/white"
android:textSize="16sp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/popular_api_fab"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginRight="16dp"
android:src="#drawable/ic_popular"
app:backgroundTint="#color/colorPrimary"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorPrimaryLight" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/api_filter_fab"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="130dp"
android:layout_marginRight="16dp"
android:src="#drawable/ic_filter"
app:backgroundTint="#color/colorPrimary"
app:borderWidth="0dp"
app:elevation="6dp"
app:layout_anchorGravity="bottom|right"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorPrimaryLight" />
</RelativeLayout>
Android Studio running code on phone auto turns off.
I am trying to build a translator application.
I think there is something wrong in my layout design but I cant figure out what.
I divided my homepage into two parts.
This is my activity_home layout.
<?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:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp"
android:background="#drawable/bwall1"
android:fitsSystemWindows="true"
tools:context="nf.co.hoptec.ocr.Home">
<ImageButton
android:id="#+id/fab"
android:layout_width="100dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:background="#drawable/roundcorner"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:layout_constraintHorizontal_bias="0.19"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="#drawable/cameraicon"
tools:layout_constraintTop_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="#+id/fab2"
app:layout_constraintTop_toTopOf="#+id/fab2" tools:targetApi="lollipop"/>
<ImageButton
android:id="#+id/fab2"
android:layout_width="100dp"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:background="#drawable/roundcorner"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/imageicon"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="72dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="47dp" tools:targetApi="lollipop"/>
<include
layout="#layout/content_home"
android:layout_width="0dp"
android:layout_height="400dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
</android.support.constraint.ConstraintLayout>
This is my content_home layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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"
android:layout_marginTop="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="nf.co.hoptec.ocr.Home"
tools:showIn="#layout/activity_home">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:visibility="visible">
<LinearLayout
android:background="#drawable/border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:visibility="visible"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/source"
android:layout_width="135dp"
android:layout_height="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="1dp"
android:background="#F7F9FC"
android:text=":: Source Language ::"
android:textColor="#000000"
android:textSize="12sp" />
<ImageButton
android:id="#+id/proceedbutt"
android:layout_width="20dip"
android:layout_height="20dip"
android:background="#00ffffff"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:srcCompat="#drawable/proceed"
android:layout_alignParentEnd="true" />
<ImageButton
android:id="#+id/speakerbutt"
android:layout_width="20dip"
android:layout_height="20dip"
android:background="#00ffffff"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:srcCompat="#drawable/speaker"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/proceedbutt"/>
<ImageButton
android:id="#+id/copy"
android:layout_width="20dip"
android:layout_height="20dip"
android:background="#00ffffff"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:srcCompat="#drawable/copy"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/speakerbutt" />
</RelativeLayout>
<EditText
android:id="#+id/ocrtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30.0dp"
android:layout_marginRight="30.0dp"
android:layout_marginTop="15dp"
android:ems="10"
android:inputType="textMultiLine"
android:selectAllOnFocus="true"
android:singleLine="true"
android:text="Type here to translate"
android:textSize="12sp"
android:layout_marginBottom="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"
android:paddingTop="10dp">
<ImageView
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:id="#+id/ocrimg" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/border"
android:orientation="vertical"
android:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/target"
android:layout_width="135dp"
android:layout_height="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="1dp"
android:background="#F7F9FC"
android:text=":: Result Language ::"
android:textColor="#000000"
android:textSize="12sp" />
<ImageButton
android:id="#+id/nth"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_alignParentEnd="true"
android:background="#00ffffff"
app:srcCompat="#drawable/xparent" />
<ImageButton
android:id="#+id/speakerbutt1"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/nth"
android:adjustViewBounds="true"
android:background="#00ffffff"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:srcCompat="#drawable/speaker" />
<ImageButton
android:id="#+id/copyt"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/speakerbutt1"
android:adjustViewBounds="true"
android:background="#00ffffff"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:srcCompat="#drawable/copy" />
</RelativeLayout>
<TextView
android:id="#+id/ocrtextt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="30.0dp"
android:layout_marginRight="30.0dp"
android:layout_marginTop="15dp"
android:background="?attr/editTextBackground"
android:ems="10"
android:inputType="textMultiLine"
android:text=""
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Can you tell me what is wrong?
I think its because of constraint layout.Constraint layout is new layout of Android in which you can just drag and drop buttons,textview and all but it may looks perfect in preview but not in your phone because every device have different size of display screen so constraint layout will work different in different android phones and you may also be getting warning or error in that layout file.So try to use LinearLayout or RelativeLayout and then errors will not come.
I am developing android application of restaurant on xamarin,so i am designing login screen
for that i added text view "USERNAME" now i want this text view to appear in center of the screen i dnt want to hard code,i want it to be responsive. please guide how can it in center as i am new to xamarin here is my code
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ddd9db"
android:theme="#style/Theme.Custom">
<TextView
android:text="UserName"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="148.0dp"
android:layout_height="37.0dp"
android:gravity="center"
android:id="#+id/textView_user"
android:fontFamily="#string/Hello"
android:textColor="#android:color/black"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24.0dp"
android:inputType="text"
android:textSize="25px"
android:textAlignment="gravity"
android:theme="#style/Theme.Custom"
android:layout_marginLeft="225dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="46.0dp"
android:id="#+id/editText_user"
android:textColor="#android:color/black"
android:fontFamily="#string/Hello"
android:background="#drawable/EditTextStyle" />
<TextView
android:text="Password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView_pass"
android:layout_marginTop="29.0dp"
android:textSize="25px"
android:fontFamily="#string/Hello"
android:textColor="#android:color/background_dark" />
<EditText
android:layout_width="match_parent"
android:layout_height="43.0dp"
android:id="#+id/editText_pass"
android:textColor="#android:color/black"
android:fontFamily="#string/Hello"
android:background="#drawable/EditTextStyle" />
<FrameLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frameLayout1" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button1"
android:textColor="#android:color/background_dark"
android:layout_marginRight="0.0dp"
android:layout_marginLeft="0.0dp"
android:theme="#style/Theme.Custom" />
</LinearLayout>
Try this code. You have to use layout width="match_parent" and gravity="center"
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ddd9db"
android:theme="#style/Theme.Custom"
android:gravity="center">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:background="#android:color/background_light">
<TextView
android:text="UserName"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="37.0dp"
android:gravity="center"
android:id="#+id/textView_user"
android:fontFamily="#string/Hello"
android:textColor="#android:color/black"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:inputType="text"
android:textSize="25px"
android:textAlignment="gravity"
android:theme="#style/Theme.Custom" />
<EditText
android:layout_width="match_parent"
android:layout_height="46.0dp"
android:id="#+id/editText_user"
android:textColor="#android:color/black"
android:fontFamily="#string/Hello"
android:background="#drawable/EditTextStyle" />
<TextView
android:text="Password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView_pass"
android:layout_marginTop="29.0dp"
android:textSize="25px"
android:fontFamily="#string/Hello"
android:textColor="#android:color/background_dark"
android:gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="43.0dp"
android:id="#+id/editText_pass"
android:textColor="#android:color/black"
android:fontFamily="#string/Hello"
android:background="#drawable/EditTextStyle" />
<FrameLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frameLayout1" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button1"
android:textColor="#android:color/background_dark"
android:layout_marginRight="0.0dp"
android:layout_marginLeft="0.0dp"
android:theme="#style/Theme.Custom" />
</LinearLayout>
</LinearLayout>