Constraint Layout Issue - android

This is the code that I keep getting an error when I try to put it into Constraint Layout. I have tried numerous different methods to allow the constraint layout to appear successfully on the profile page. However, I still have been unsuccessful with getting the name to display without being jumbled together.
<?xml version="1.0" encoding="utf-8"?>
<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:background="#color/graylight"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="260dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#drawable/gradientbackground"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="425dp"
android:scaleType="centerInside"
android:src="#drawable/jussim" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Justina Simone"
android:textColor="#fff"
android:textSize="21sp"
android:textStyle="bold" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/IVaddfriend"
android:layout_width="425dp"
android:layout_height="85dp"
android:src="#drawable/ic_person_add_black_24dp" />
<ImageView
android:id="#+id/IVimage1"
android:layout_width="425dp"
android:layout_height="85dp"
android:src="#drawable/ic_message_black_24dp"
tools:ignore="InvalidId" />
<ImageView
android:id="#+id/IVimage2"
android:layout_width="425dp"
android:layout_height="85dp"
android:src="#drawable/ic_grade_black_24dp"/>
</LinearLayout>

Related

How to shift text below the circle using given XML code?

I am using below XML code with card and RecyclerView but I am getting the text inside the card and upper side But I would like to see the text below the circle, what changes should I make in the following XML code?
Reference image consists with current and desire output image as
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="5dp">
<!--
grid items for RecyclerView
-->
<androidx.cardview.widget.CardView
android:id="#+id/myCardView"
android:layout_width="110dp"
android:layout_height="110dp"
app:cardCornerRadius="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="ABCD"
android:textSize="20sp"
android:textColor="#fff" />
</androidx.cardview.widget.CardView>
</RelativeLayout>
You can get the TextView out of the CardView in order to have the ImageView fully occupy the entire area of the rounded CardView
<?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="200dp"
android:gravity="center"
android:padding="5dp">
<!--
grid items for RecyclerView
-->
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/myCardView"
android:layout_centerHorizontal="true"
android:textColor="#fff"
android:text="ABCD"
android:textSize="20sp" />
<androidx.cardview.widget.CardView
android:id="#+id/myCardView"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_centerHorizontal="true"
app:cardCornerRadius="50dp">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#mipmap/ic_launcher" />
</androidx.cardview.widget.CardView>
</RelativeLayout>
Preview
CardView can accept only 1 direct child so you need to wrap your views with another ViewGroup as following:
<?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="200dp"
android:padding="5dp">
<!--
grid items for RecyclerView
-->
<androidx.cardview.widget.CardView
android:id="#+id/myCardView"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:cardCornerRadius="50dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/image"
android:layout_centerHorizontal="true"
android:text="ABCD"
android:textColor="#000"
android:textSize="20sp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
And then you can adjust gravity of your view to your needs.
<?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="200dp"
android:gravity="center"
android:padding="5dp">
<androidx.cardview.widget.CardView
android:id="#+id/myCardView"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_centerInParent="true"
app:cardCornerRadius="60dp">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#mipmap/ic_launcher" />
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/myCardView"
android:layout_marginTop="0dp"
android:text="ABCD"
android:textAlignment="center"
android:textSize="20sp" />
</RelativeLayout>

How to dynamically change button size?

I am trying to make the size of both button equal but as I change the screen below button size increase as you can see in the Image.
Click here to view Image
Here is the Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#android:color/black"
tools:context=".Timer">
<Button
android:id="#+id/player1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#696969"
android:text="00:00"
android:textSize="95sp" />
<RelativeLayout
android:id="#+id/rl1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="#+id/player1">
<ImageButton
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_baseline_pause_circle_outline_24"
android:scaleType="centerCrop"
android:background="#android:color/transparent"/>
</RelativeLayout>
<Button
android:id="#+id/player2"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="#+id/rl1"
android:layout_alignParentBottom="true"
android:background="#696969"
android:text="00:00"
android:textSize="95sp" />
</RelativeLayout>
Use LinearLayout as parent and provide with weight to children to achieve the result.
<?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:background="#android:color/black"
android:orientation="vertical"
tools:context=".Timer">
<Button
android:id="#+id/player1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#696969"
android:text="00:00"
android:layout_weight="0.3"
android:textSize="95sp" />
<RelativeLayout
android:id="#+id/rl1"
android:layout_width="match_parent"
android:layout_height="0dp">
<ImageButton
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_baseline_pause_circle_outline_24"
android:scaleType="centerCrop"
android:background="#android:color/transparent"/>
</RelativeLayout>
<Button
android:id="#+id/player2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#696969"
android:text="00:00"
android:layout_weight="0.3"
android:textSize="95sp" />

How do I center a button inside of a LinearLayout, contained by a RelativeLayout?

This is the code I have now. My button at the bottom is what is giving me problems. I have tried some options online but have not had any success. Knowing me it is probably some thing simple. Online examples work but do not accommodate my situating at hand.
```
<?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="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">
<VideoView
android:id="#+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="true"
android:layout_alignParentRight="false"
android:layout_alignParentBottom="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:background="#61414440"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="60dp"
android:gravity="center_horizontal"
android:text="Amaquiz"
android:textColor="#fff"
android:textSize="50sp"
android:textStyle="bold"
app:fontFamily="cursive" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal|center_vertical"
android:gravity="center|center_horizontal"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
```

"Encasing" a map in a FrameLayout in an android app

I'm trying to create a vertical LinearLayout of elements as follows:
A text view (weight 0.05)
A map (weight 0.85)
A horizontal layout of edit field and button
So far it seems OK, but now I'm trying to put the map within a FrameLayout so that I can append child views to it, but when I do so, the map no longer appears. Can anyone help?
My layout.xml file is below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:id="#+id/tlll"
>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".05"
android:background="#000000"
android:text="UK Map"
android:textColor="#ffffff"
android:gravity="center"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/frlayout"
android:layout_weight=".85"
android:layout_width="match_parent"
android:layout_height="0dp"
>
<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="0dp"
android:layout_height="0dp"
tools:context=".MapShow" />
</FrameLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".10"
android:background="#004D79"
android:orientation="horizontal">
<EditText
android:id="#+id/addressText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="7dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:text="Enter address">
</EditText>
<Button
android:id="#+id/findButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:text="Find">
</Button>
</LinearLayout>
The weights look fine, and it seems to be a problem with the layout heights and widths, but I can't see what is wrong.
Your fragment width and height are zero. Try to increase them.
You can achieve this by RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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=".activity.MapsActivity" />
<RelativeLayout
android:id="#+id/relLayout1"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#drawable/border_black"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:elevation="10dp">
<ImageView
android:id="#+id/ic_magnify"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_magnify" />
<AutoCompleteTextView
android:id="#+id/input_search"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ic_magnify"
android:background="#null"
android:hint="Enter Address, City or Zip Code"
android:imeOptions="actionSearch"
android:textColor="#000"
android:textSize="15sp" />
<ImageView
android:id="#+id/ic_gps"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:layout_toLeftOf="#+id/map_location_db"
android:src="#drawable/ic_pin" />
<ImageView
android:id="#+id/map_location_db"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:src="#drawable/ic_datebase" />
</RelativeLayout>
<ImageView
android:visibility="gone"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="#id/relLayout1"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_gps" />
<ImageView
android:visibility="gone"
android:id="#+id/place_picker"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="#+id/relLayout1"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_map" />
<ImageView
android:visibility="gone"
android:id="#+id/place_info"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="#+id/place_picker"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_info" />

Custom row with circular ImageView and textview in android

I am trying to create a custom row for my RecyclerView. Here is my custom row layout:
<?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="180dp"
android:layout_margin="5dp"
android:background="#00000000">
<FrameLayout
android:id="#+id/customLevelLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/levelImage"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_above="#+id/gameText"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:src="#drawable/circular_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="1"
android:textColor="#fff"
android:textSize="45sp" />
<TextView
android:id="#+id/gameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:textColor="#000"
tools:text="Tracing" />
</RelativeLayout>
<ProgressBar
android:id="#+id/gameProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:indeterminate="true"
android:padding="45dp"
android:visibility="gone" />
</FrameLayout>
<ImageView
android:id="#+id/lockImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/lock_background"
android:padding="45dp"
android:src="#drawable/lock"
android:visibility="gone" />
</RelativeLayout>
This is how it looks like:
The problem is, I have to define a predefined height of the custom row i.e 170dp currently. I am facing 2 problems because of this:
1) If I open the application in a small screen or a tablet device. The custom row is looking ugly i.e I loose the circular shape of the ImageView.
2) The text doesn't remain at the centre if there is a slight change in the layout.
Try this in your code .
<?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="wrap_content"
android:layout_margin="5dp"
android:background="#00000000">
<FrameLayout
android:id="#+id/customLevelLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/levelImage"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:src="#drawable/circular_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="1"
android:textColor="#fff"
android:textSize="45sp"/>
</RelativeLayout>
<TextView
android:id="#+id/gameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:textColor="#000"
tools:text="Tracing"/>
</LinearLayout>
<ProgressBar
android:id="#+id/gameProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:indeterminate="true"
android:padding="45dp"
android:visibility="gone"/>
</FrameLayout>
<ImageView
android:id="#+id/lockImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/lock_background"
android:padding="45dp"
android:src="#drawable/lock"
android:visibility="gone" />
</RelativeLayout>
Try This. You can use Linearlayout as root than for image and text use RelativeLayout
<?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="wrap_content"
android:layout_margin="5dp"
android:background="#00000000"
android:orientation="vertical">
<FrameLayout
android:id="#+id/customLevelLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/levelImage"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:src="#drawable/circular_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="1"
android:textColor="#fff"
android:textSize="45sp" />
</RelativeLayout>
<TextView
android:id="#+id/gameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:gravity="center"
android:textColor="#000"
tools:text="Tracing" />
</LinearLayout>
<ProgressBar
android:id="#+id/gameProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:indeterminate="true"
android:padding="45dp"
android:visibility="gone" />
</FrameLayout>
<ImageView
android:id="#+id/lockImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/lock_background"
android:padding="45dp"
android:src="#drawable/lock"
android:visibility="gone" />
</LinearLayout>
Use constrain layout which helps you to set image like you want just by drag and drop and add constrain
For supporting multiple screen. First you have to go through this link
enter link description here
Once you fix first issue, second issue also will get fix

Categories

Resources