I created a custom view and when I use it on another layout the layout_gravity on the ImageView is not working.
heres the code
<?xml version="1.0" encoding="utf-8"?>
<merge 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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/text_size_semi_large"
android:clickable="false"
android:visibility="gone"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
app:cardPreventCornerOverlap="true"
app:cardCornerRadius="2dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/card_background_white"
android:padding="#dimen/activity_padding">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="#dimen/drawable_padding"
android:layout_marginEnd="#dimen/drawable_padding" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:textColor="#color/warm_gray"
android:textSize="#dimen/text_size_semi_large"
android:text="Two line \n Text"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="#dimen/drawable_padding"
android:layout_marginLeft="#dimen/drawable_padding"
android:src="#drawable/ic_arrow_right_material"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
this is the output
and this is the output when I use the custom view in another layout
Try this Showed Fine For me
<?xml version="1.0" encoding="utf-8"?>
<merge 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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/text_size_semi_large"
android:clickable="false"
android:visibility="gone"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
app:cardPreventCornerOverlap="true"
app:cardCornerRadius="2dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="#drawable/card_background_white"
android:padding="#dimen/activity_padding">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="#dimen/drawable_padding"
android:layout_marginEnd="#dimen/drawable_padding" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:textColor="#color/warm_gray"
android:textSize="#dimen/text_size_semi_large"
android:text="Two line \n Text"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="#dimen/drawable_padding"
android:layout_marginLeft="#dimen/drawable_padding"
android:src="#drawable/ic_arrow_right_material"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Related
Hello! as the title suggest, I'm trying to put those two CardViews next to each other. Is it possible to do so. Currently this is what my xml looks like. Here's the 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:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/homeBackground"
android:orientation="vertical"
tools:context=".Home">
<LinearLayout
android:orientation="horizontal"
android:id="#+id/layout_user_information"
android:weightSum="4"
android:padding="8dp"
android:background="#color/colorButton"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/home_image"
app:srcCompat="#drawable/userboy"
android:layout_width="60dp"
android:layout_height="60dp" />
<LinearLayout
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id = "#+id/home_username"
android:text = "Username"
android:textColor="#android:color/white"
android:textSize="22sp"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:weightSum="4">
<androidx.cardview.widget.CardView
android:id="#+id/card_view_booking"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="8dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/home_booking" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/poppinsbold"
android:text="Booking" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:weightSum="4"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_history"
android:layout_marginRight="8dp"
android:layout_width="0dp"
android:layout_weight="1"
app:cardCornerRadius="8dp"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:srcCompat="#drawable/home_history"
android:layout_width="50dp"
android:layout_gravity="center_horizontal"
android:layout_height="50dp" />
<TextView
android:text="History"
android:fontFamily="#font/poppinsbold"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
I have already match_parent for both layout width and height for the first LinearLayout. but no luck there. Is there any way I could solve this problem?
wrap the both layout that contains CardView with another linear Layout with
android:orientation="horizontal"
the whole code will look like
<?xml version="1.0" encoding="utf-8"?><?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/homeBackground"
android:orientation="vertical"
tools:context=".Home">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:weightSum="4">
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_booking"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/home_booking" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/poppinsbold"
android:text="Booking" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:weightSum="4">
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_history"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/home_history" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/poppinsbold"
android:text="History" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Use a linear layout with orientation = "horizontal" and have the card view placed under it
This is what I'm trying to achieve
And this is what I have so far and the code below is the code for this screenshot
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="270dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/imageView"
android:textColor="#000000"
android:textSize="40sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Basically, I can't figure out how to get the image outside but still touching the card. Any help is appreciated, thanks.
You can use FrameLayout and elevation to fulfill your target.
According to the documentation of FrameLayout
Child views are drawn in a stack, with the most recently added child
on top
You need to play with the elevation of the ImageView to bring it above the CardView.
This is what I have achieved: You can then modify your paddings/margins according to design.
Code:
<?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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
app:cardCornerRadius="4dp"
app:cardBackgroundColor="#android:color/holo_blue_bright"
android:layout_width="308dp"
android:layout_height="112dp"
android:layout_gravity="right"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_marginStart="40dp"
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:paddingLeft="8dp"
android:text="EARTH"
android:textColor="#000000"
android:textSize="70sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<ImageView
android:src="#drawable/planet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:elevation="2dp" />
</FrameLayout>
</LinearLayout>
Try this layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/first"
app:cardBackgroundColor="#android:color/white"
app:cardCornerRadius="#dimen/cardview_default_radius"
app:cardElevation="4dp"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginLeft="50dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEXT"
android:textSize="18sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="32dp"
android:background="#000000"
android:layout_marginTop="15dp"
android:contentDescription="#null"/>
</RelativeLayout>
Result:
I have a screen in which there is a toolbar, a bottomNavigationView and some data between them including a textView and an imageView. I want to scroll the inner data that is between the toolbar and bottomNavigationView.
I want to scroll the design.xml inside of main.xml. Please suggest a way I can achieve this.
main.xml
<?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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar1"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<include
layout="#layout/design"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#FFFFFF"
app:itemTextColor="#FFFFFF"
app:menu="#menu/bottom_navigation_main" />
design.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="?android:attr/actionBarSize"
tools:context="com.example.chaitanya.pg.Pgdata">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relative">
<Button
android:id="#+id/btt1"
android:background="#drawable/tprevoius"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="100dp" />
<Button
android:background="#drawable/tnext"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignTop="#+id/btt1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/btt2" />
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/viewPager"/>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview1"
android:layout_width="match_parent"
android:layout_height="100dp"
card_view:cardElevation="5dp"
android:layout_below="#id/viewPager"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Facilities"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:id="#+id/facilities"
android:textSize="20dp"
android:gravity="center"
android:layout_below="#+id/viewPager"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:paddingLeft="10dp"
android:textSize="15dp"
android:id="#+id/wifi"
/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="15dp"
android:id="#+id/ac"
/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:foregroundGravity="right"
android:paddingLeft="20dp"
android:id="#+id/food"
android:textStyle="bold"
android:textSize="15dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview12"
android:layout_width="match_parent"
android:layout_height="60dp"
card_view:cardElevation="5dp"
android:layout_below="#id/cardview1"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accomodation"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:textSize="20dp"
android:gravity="center"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="20dp"
android:id="#+id/accomodation"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview123"
android:layout_width="match_parent"
android:layout_height="60dp"
card_view:cardElevation="5dp"
android:layout_below="#id/cardview12"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Price"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:textSize="20dp"
android:gravity="center"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="20dp"
android:id="#+id/pricee"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:id="#+id/name"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:textSize="20dp"
android:layout_marginLeft="10dp"
android:paddingLeft="20dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:id="#+id/addr"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:layout_marginLeft="10dp"
android:textSize="20dp"
/>
</RelativeLayout>
</LinearLayout>
There needs to be only one layout inside ScrollView.
You do not need to put ScrollView inside ScrollView.
You have added the include tag inside the ScrollView and your
design.xml also has ScrollView.
I would not use android:fillViewport tag inside ScrollView, instead
use properties related to relative layout.
Rest of the things don't seem too difficult to figure out.
from design.xml remove parent <ScrollView> because outsie you already define the scrollview so there is no use of scrollview inside the design.xml
design.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
My xml layout design is not what it is supposed to be from my code. I am not changing anything dynamically.
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp"/>
<TextView
android:id="#+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rollnoT"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp"/>
<TextView
android:id="#+id/cmtT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="#android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
My design:
Look at "abc" It should be below '5' not in mid.
I have set android:layout_below="#+id/rollnoT"
but still it is shown in mid.
Pls help me solve this issue.
Try this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp"/>
<TextView
android:id="#+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rollnoT"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp"/>
<TextView
android:id="#+id/cmtT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="#android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
Try this blow snippet,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp" />
<TextView
android:id="#+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rollnoT"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp" />
</LinearLayout>
<TextView
android:id="#+id/cmtT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="#android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
It would be great if you have practice about LinearLayout. It solves lots of issues. If you are using RelativeLayout then it is dependable on other views.
I am trying to place a RelativeLayout having two ImageButtons inside a FrameLayout which already has a ImageView and a LinearLayout. I have to place the Relative Layout in such a way that vertically upper half of the ImageButton should be overlapping ImageView and lower half overlapping LinearLayout.
My current layout is like this:
My current xml is:
<?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:background="#f2f2f2"
android:elevation="8dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#fff"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="180dp"
android:src="#drawable/fire_icon" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorblue"
android:orientation="vertical"
android:padding="10dp"
android:layout_margin="10dp">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Need Help"
android:textColor="#color/colortitletext"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Hello, I am trying to create a android layout."
android:textColor="#color/colorheadtext"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:layout_marginRight="15dp">
<ImageView
android:id="#+id/imageView4"
android:layout_width="60dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/imageView3"
android:layout_toStartOf="#+id/imageView3"
android:src="#drawable/ic_menu_camera" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="60dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_menu_gallery" />
</RelativeLayout>
</FrameLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Expected Layout is:
Have look i edit your layout ......
i think that is what you want ..........
<?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="wrap_content"
android:background="#f2f2f2"
android:elevation="8dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#fff"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="180dp"
android:src="#drawable/fire_icon"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#AACCAA"
android:orientation="vertical"
android:padding="10dp"
android:layout_margin="10dp">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Need Help"
android:textColor="#color/colortitletext"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Hello, I am trying to create a android layout."
android:textColor="#color/colorheadtext"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f2f2f2"
android:layout_marginTop="160dp"
android:layout_marginLeft="200dp">
<ImageView
android:id="#+id/imageView4"
android:layout_width="60dp"
android:layout_height="50dp"
android:src="#drawable/ic_menu_gallery"/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="60dp"
android:layout_height="50dp"
android:src="#drawable/ic_menu_camera"/>
</LinearLayout>
</FrameLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
enjoy coding...........