The layouts and elements in Android Studio look exactly how I want it to be but as soon as I install the APK on my device, the layout collapses. All views are collapsed one on top of another which is not what was shown in Android Studio's preview...
I'm using linear layouts and relative layout. I had used android studio 1-2yrs ago and there was no such thing as constrained layout, now every time I create a layout I get an constrained error.
XML Main activity (only one):
<?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:context="com.simultaneousequations.spacelaunchx.spacelaunchx.MainActivity">
<LinearLayout
android:id="#+id/linearLayoutTop"
android:layout_width="0dp"
android:layout_height="101dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="11dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="#+id/linearLayoutCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="#+id/relativeLayoutTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorLightGrey">
<LinearLayout
android:id="#+id/linearLayoutTopImage"
android:layout_width="110dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/iridumNEXT40_50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:adjustViewBounds="false"
android:cropToPadding="false"
android:scaleType="fitStart"
app:srcCompat="#mipmap/iridiummission5" />
</LinearLayout>
<TextView
android:id="#+id/iridium5Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"
android:layout_toEndOf="#+id/linearLayoutTopImage"
android:layout_toRightOf="#+id/linearLayoutTopImage"
android:fontFamily="sans-serif-condensed"
android:text="Iridium NEXT 40 50"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/colorRedDragon"
android:textSize="16sp"
android:textStyle="bold|italic" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutCenter"
android:layout_width="400dp"
android:layout_height="101dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="101dp"
android:background="#color/colorLightGrey"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="109dp">
<LinearLayout
android:id="#+id/linearLayoutCenterImage"
android:layout_width="110dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/crs14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:scaleType="fitStart"
app:srcCompat="#mipmap/crs14" />
</LinearLayout>
<TextView
android:id="#+id/crs14Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ndroid:layout_marginTop="16dp"
android:layout_toEndOf="#+id/linearLayoutCenterImage"
android:layout_toRightOf="#+id/linearLayoutCenterImage"
android:fontFamily="sans-serif-condensed"
android:text="SpaceX NASA - CRS-14"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/colorRedDragon"
android:textSize="18sp"
android:textStyle="bold|italic" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutCenterBottom"
android:layout_width="400dp"
android:layout_height="101dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="101dp"
android:background="#color/colorLightGrey"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="109dp">
<LinearLayout
android:id="#+id/linearLayoutCenterBottomImage"
android:layout_width="110dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/bhu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:scaleType="fitCenter"
app:srcCompat="#mipmap/spacexlogo"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="101dp" />
</LinearLayout>
<TextView
android:id="#+id/bhuText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"
android:layout_toEndOf="#+id/linearLayoutCenterBottomImage"
android:layout_toRightOf="#+id/linearLayoutCenterBottomImage"
android:fontFamily="sans-serif-condensed"
android:text="Bangabandhu-1"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/colorRedDragon"
android:textSize="18sp"
android:textStyle="bold|italic" />
</RelativeLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
What am I doing wrong?
Seems like you're not familiar with ConstraintLayout.
That's OK. Don't use ConstraintLayout when you don't want to use it. Using this is not necessary.
What you have to do is just change the root layout to either LinearLayout, RelativeLayout or any other Layout you want to use as per your requirements.
I'm giving you the code that you should use in this case. In that code, I'm using RelativeLayout as the root layout, because you are using layout_alignParentBottom like attributes.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.companys.appx.appx.MainActivity">
<LinearLayout
android:id="#+id/linearLayoutTop"
android:layout_width="0dp"
android:layout_height="101dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="11dp"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/relativeLayoutTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorLightGrey">
<LinearLayout
android:id="#+id/linearLayoutTopImage"
android:layout_width="110dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/iridumNEXT40_50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:adjustViewBounds="false"
android:cropToPadding="false"
android:scaleType="fitStart"
app:srcCompat="#mipmap/iridiummission5" />
</LinearLayout>
<TextView
android:id="#+id/iridium5Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"
android:layout_toEndOf="#+id/linearLayoutTopImage"
android:layout_toRightOf="#+id/linearLayoutTopImage"
android:fontFamily="sans-serif-condensed"
android:text="Iridium NEXT 40 50"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/colorRedDragon"
android:textSize="16sp"
android:textStyle="bold|italic" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutCenter"
android:layout_width="400dp"
android:layout_height="101dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="101dp"
android:background="#color/colorLightGrey"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="109dp">
<LinearLayout
android:id="#+id/linearLayoutCenterImage"
android:layout_width="110dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/crs14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:scaleType="fitStart"
app:srcCompat="#mipmap/crs14" />
</LinearLayout>
<TextView
android:id="#+id/crs14Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:layout_toEndOf="#+id/linearLayoutCenterImage"
android:layout_toRightOf="#+id/linearLayoutCenterImage"
android:fontFamily="sans-serif-condensed"
android:text="SpaceX NASA - CRS-14"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/colorRedDragon"
android:textSize="18sp"
android:textStyle="bold|italic" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutCenterBottom"
android:layout_width="400dp"
android:layout_height="101dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="101dp"
android:background="#color/colorLightGrey"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="109dp">
<LinearLayout
android:id="#+id/linearLayoutCenterBottomImage"
android:layout_width="110dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/bhu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:scaleType="fitCenter"
app:srcCompat="#mipmap/spacexlogo"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="101dp" />
</LinearLayout>
<TextView
android:id="#+id/bhuText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="12dp"
android:layout_toEndOf="#+id/linearLayoutCenterBottomImage"
android:layout_toRightOf="#+id/linearLayoutCenterBottomImage"
android:fontFamily="sans-serif-condensed"
android:text="Bangabandhu-1"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/colorRedDragon"
android:textSize="18sp"
android:textStyle="bold|italic" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
If there is any mistake(typo) in the code change it.
The only point is to use RelativeLayout as the root Layout instead of ConstraintLayout
In the above code, I've removed all the ConstraintLayout Attributes from the first LinearLayout because the root Layout is no more a ConstraintLayout.
This Trick will remove the problem. The problem was occurring because ContraintLayout has its own rules that you were not following. But now as you've changed the root Layout the problem will no longer exist.
Related
enter image description here
As you can see there is a shadow around the ticket. I cannot make this because I am using the library (TicketView) and there is a problem with Scallops
HERE IS MY CODE
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#f3f6f9">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="52.5dp"
android:layout_marginEnd="18dp"
android:orientation="vertical"
android:elevation="14dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="37.5dp"
android:background="#drawable/gradient_tickets">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="10dp"
android:elevation="2dp"
android:text="Bus 79"
android:textColor="#fefefe"
android:textSize="12sp"
tools:layout_editor_absoluteX="37dp"
tools:layout_editor_absoluteY="69dp" />
<ImageView
android:id="#+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:scaleX="0.6"
android:scaleY="0.6"
android:src="#drawable/arrow_list" />
<TextView
android:id="#id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/text1"
android:layout_marginTop="40dp"
android:layout_marginBottom="10dp"
android:text="11/03/2017"
android:textColor="#a4158a"
android:textSize="12sp" />
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/img1"
android:layout_alignParentRight="false"
android:layout_alignParentBottom="false"
android:layout_marginTop="40dp"
android:text="$0.30"
android:textColor="#a4158a"
android:textSize="12sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.vipulasri.ticketview.TicketView
android:id="#+id/ticketView"
android:layout_width="wrap_content"
android:layout_height="142dp"
app:ticketBackgroundColor="#FFFFFF"
app:ticketDividerColor="#16191c"
app:ticketDividerDashGap="4dp"
app:ticketDividerDashLength="3dp"
app:ticketDividerPadding="1.5dp"
app:ticketDividerType="dash"
app:ticketDividerWidth="0.5dp"
app:ticketOrientation="horizontal"
app:ticketScallopPositionPercent="25.7"
app:ticketScallopRadius="7dp"
app:ticketShowBorder="false"
app:ticketShowDivider="true"
/>
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20.5dp"
android:layout_marginTop="16.5dp"
android:elevation="2dp"
android:text="12/03/2017"
android:textColor="#a4158a"
android:textSize="10sp" />
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/ticketView"
android:layout_alignRight="#+id/ticketView"
android:layout_marginTop="16.5dp"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:elevation="2dp"
android:text="$0.30"
android:textColor="#a4158a"
android:textSize="10sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="31dp"
android:layout_marginTop="47dp"
android:layout_marginRight="31dp"
android:layout_marginBottom="45dp"
android:elevation="3dp"
android:src="#drawable/barcode_img" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
I need to have a shadow there but I cannot manage to do it. Also I used the TicketView which is for making the form of the ticket. Could u please say what I need to add there in order to have such a shadow?
You can use CardView. There is a parameter which app:cardElevation.
But if it's not possible, You can create a drawable and you can create shadow with using gradient.
I have below layout
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/searchScreenBG">
<RelativeLayout
android:id="#+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="#dimen/_7sdp">
<ImageButton
android:id="#+id/ib_hamburger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="#dimen/_16sdp"
android:layout_marginRight="#dimen/_16sdp"
android:layout_marginTop="#dimen/_15sdp"
android:background="#android:color/transparent"
android:contentDescription="#null"
app:srcCompat="#drawable/ham_burger" />
<com.rod.com.rod.ui.views.CTextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/ib_hamburger"
android:layout_centerHorizontal="true"
android:text="#string/basic_details"
android:textColor="#color/colorGreen" />
<ImageButton
android:id="#+id/ib_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/ib_hamburger"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginStart="#dimen/_16sdp"
android:background="#android:color/transparent"
android:contentDescription="#null"
app:srcCompat="#drawable/left_arrow" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/reg_no_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_5sdp"
android:layout_below="#+id/title_bar"
android:background="#color/colorWhite">
<TextView
android:id="#+id/tv_reg_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:textColor="#color/colorLightGrey" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/reg_no_layout"
>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_marginRight="#dimen/_10sdp"
android:layout_marginLeft="#dimen/_10sdp"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/basic_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/_10sdp"
android:background="#drawable/list_item_bg"
android:paddingBottom="#dimen/_10sdp">
<TextView
android:id="#+id/tv_district_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="11dp"
android:text="#string/district"
android:textColor="#color/colorBlack"
android:textSize="#dimen/_13sdp" />
<TextView
android:id="#+id/tv_district"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_district_label"
android:layout_alignStart="#+id/tv_district_label"
android:layout_below="#+id/tv_district_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
<TextView
android:id="#+id/tv_tehsil_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tv_district"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="75dp"
android:layout_marginRight="75dp"
android:text="#string/tehsil"
android:textColor="#color/colorBlack" />
<TextView
android:id="#+id/tv_tehsil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/tv_district"
android:layout_alignLeft="#+id/tv_tehsil_label"
android:layout_alignStart="#+id/tv_tehsil_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
<TextView
android:id="#+id/tv_date_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_district"
android:layout_alignStart="#+id/tv_district"
android:layout_below="#+id/tv_district"
android:layout_marginTop="13dp"
android:text="#string/date"
android:textColor="#color/colorBlack" />
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_date_label"
android:layout_alignStart="#+id/tv_date_label"
android:layout_below="#+id/tv_date_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
<TextView
android:id="#+id/tv_jild_no_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/tv_date_label"
android:layout_alignLeft="#+id/tv_tehsil"
android:layout_alignStart="#+id/tv_tehsil"
android:text="#string/jild_no"
android:textColor="#color/colorBlack" />
<TextView
android:id="#+id/tv_jild_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_jild_no_label"
android:layout_alignStart="#+id/tv_jild_no_label"
android:layout_below="#+id/tv_jild_no_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
<TextView
android:id="#+id/tv_party_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_date"
android:layout_alignStart="#+id/tv_date"
android:layout_below="#+id/tv_date"
android:layout_marginTop="13dp"
android:text="#string/party"
android:textColor="#color/colorBlack" />
<TextView
android:id="#+id/tv_party"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_party_label"
android:layout_alignStart="#+id/tv_party_label"
android:layout_below="#+id/tv_party_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_below="#+id/basic_details"
android:layout_marginTop="13dp"
android:background="#drawable/list_item_bg">
<TextView
android:id="#+id/tv_member_details_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="#dimen/_40sdp"
android:layout_marginStart="#dimen/_40sdp"
android:layout_marginTop="14dp"
android:text="#string/member_details"
android:textColor="#color/colorBlack"
android:textSize="#dimen/_16sdp" />
<ListView
android:id="#+id/lv_members"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv_member_details_label"
android:layout_marginLeft="#dimen/_40sdp"
android:layout_marginRight="#dimen/_40sdp"
android:layout_marginStart="#dimen/_40sdp"
android:layout_marginTop="16dp"
android:divider="#color/colorLightGrey"
android:dividerHeight="#dimen/_1sdp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>
I want to make the relative layout below basic_layout cover the whole of the rest screen. How can I achieve that. After searching I had found that I should put a linear layout inside my scroll view, and then relative layouts should added. But that's of no help.
I want hierachy something like below:
----RelativeLayout
-------TitleBar
-------TextView
-------ScrollView (rest of screen)
----------RelativeLayout (upper portion of scroll view)
------------TextViews
----------RelativeLayout (rest of scrol view)
-------------TextView
-------------ListView
Any help please?
Actually the problem is that you are using 2 layouts in your scrollview so the listview won't take the scroll of itself and it will limit the list height as well. To go around this you need to pass fix value to your listview then it will show completely within that specified height. And the rest of the layout if you want to get exactly as you have shown in the picture you need to use cardview instead.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_below="#+id/basic_details"
android:layout_marginTop="13dp"
android:layout_marginBottom="10dp"
android:background="#drawable/list_item_bg">
<TextView
android:id="#+id/tv_member_details_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="#dimen/_40sdp"
android:layout_marginStart="#dimen/_40sdp"
android:layout_marginTop="14dp"
android:text="#string/member_details"
android:textColor="#color/colorBlack"
android:textSize="16dp" />
<ListView
android:id="#+id/lv_members"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv_member_details_label"
android:layout_marginLeft="#dimen/_40sdp"
android:layout_marginRight="#dimen/_40sdp"
android:layout_marginStart="#dimen/_40sdp"
android:layout_marginTop="16dp"
android:divider="#color/colorLightGrey"
android:dividerHeight="#dimen/_1sdp" />
</RelativeLayout>
I've a CardView with some corner radius inside which are three relative layouts. When I set background of the layout whose top is aligned with the top of CardView, corner radius is lost.
How to keep corner radius?
Code:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="true"
app:cardCornerRadius="10dp"
android:clipToPadding="true"
app:cardPreventCornerOverlap="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rlBase"
android:clipChildren="true"
android:clipToPadding="true"
android:animateLayoutChanges="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/rlOverallPerformance"
android:background="#color/lightBlue"
android:clipToPadding="false"
android:clipChildren="false">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/rlRealizedValue"
android:layout_below="#+id/rlOverallPerformance">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/rlUnrealizedValue"
android:layout_below="#+id/rlRealizedValue"
android:elevation="1dp">
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
Surround your CardView with other ViewGroup element like FrameLayout, LinearLayout or RelativeLayout. Even I faced same problem, then it worked this way. I read it somewhere.
File: listitem_screen.xml
<?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="wrap_content">
<include layout="#layout/listitem_screen_base" />
</RelativeLayout>
I am using <include> tag as I am using same layout at different places.
File: listitem_screen_base.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/windowBackground"
app:cardCornerRadius="#dimen/rect_corner_radius"
app:cardElevation="#dimen/cardview_default_elevation"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<LinearLayout
android:id="#+id/ll_base"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.company.app.custom.CustomImageView
android:id="#+id/img_poster"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#color/black3"
app:calculation_type="height"
app:ratio_height="#integer/inspire_img_height_ratio"
app:ratio_width="#integer/inspire_img_width_ratio"
app:riv_corner_radius_top_left="#dimen/rect_corner_radius"
app:riv_corner_radius_top_right="#dimen/rect_corner_radius" />
<com.company.app.custom.FontTextView
android:id="#+id/lbl_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="20dp"
android:background="#drawable/shape_rect_round_border_right_yellow_fill"
android:paddingBottom="2dp"
android:paddingEnd="6dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingStart="6dp"
android:paddingTop="2dp"
android:text="#string/s_new"
android:textColor="?android:attr/textColorPrimary"
android:textSize="9.72sp"
app:customFont="#string/font_circular_book" />
</FrameLayout>
<com.company.app.custom.FontTextView
android:id="#+id/lbl_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginBottom="13dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:ellipsize="end"
android:gravity="center_vertical|start"
android:maxLines="2"
android:minHeight="38dp"
android:textAlignment="viewStart"
android:textColor="?android:textColorPrimaryInverse"
android:textSize="16sp"
app:customFont="#string/font_circular_book" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="13dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp">
<com.company.app.custom.FontTextView
android:id="#+id/lbl_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="?android:attr/textColorTertiary"
android:textSize="12sp"
app:customFont="#string/font_avenir_medium" />
<ImageView
android:id="#+id/dot1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginStart="14dp"
android:layout_toEndOf="#+id/lbl_time"
android:layout_toRightOf="#+id/lbl_time"
android:scaleType="centerInside"
android:src="#drawable/dot" />
<com.company.app.custom.FontTextView
android:id="#+id/lbl_views"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/dot1"
android:layout_toRightOf="#+id/dot1"
android:textColor="?android:attr/textColorTertiary"
android:textSize="12sp"
app:customFont="#string/font_avenir_medium" />
<ImageView
android:id="#+id/dot2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginStart="14dp"
android:layout_toEndOf="#+id/lbl_views"
android:layout_toRightOf="#+id/lbl_views"
android:scaleType="centerInside"
android:src="#drawable/dot" />
<com.company.app.custom.FontTextView
android:id="#+id/lbl_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/dot2"
android:layout_toRightOf="#+id/dot2"
android:textColor="#color/colorAccent"
android:textSize="12sp"
app:customFont="#string/font_avenir_medium" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
So in my program i have a layout implemented in which i want the image to alignTop of the parent. I used to exact same layout code for another activity (with minor changes) and it works perfectly but when using it in this activity it does not. My image still aligns to the center fo the view. Here is the layout 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/darkGray"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.intellidev.fuzionvapor.HomeDetails"
tools:showIn="#layout/activity_home_details">
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/homeDetailsActivityTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/homeDetailsActivityImage"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/homeDetailsActivityPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/homeDetailsActivityImage"
android:textColor="#color/fuzionRed"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:id="#+id/homeDetailsActivityRuler"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="#+id/homeDetailsActivityTitle"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#color/white" />
<TextView
android:id="#+id/homeDetailsActivityDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/homeDetailsActivityRuler"
android:textColor="#color/white"
android:textSize="15sp" />
<LinearLayout
android:id="#+id/homeDetailsFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/homeDetailsActivityButton"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/homeDetailsActivitySizeSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="1dp"
android:layout_weight="1"
app:ms_arrowColor="#color/fuzionRed"
app:ms_arrowSize="16dp"
app:ms_baseColor="#color/fuzionRed"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelColor="#color/fuzionRed"
app:ms_floatingLabelText="#string/sizeFloatingLabel"
app:ms_highlightColor="#color/fuzionRed"
app:ms_hintColor="#color/fuzionRed"
app:ms_hint="Size"
app:ms_multiline="false"
app:ms_thickness="1dp" />
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/homeDetailsActivityNicotineSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
app:ms_arrowColor="#color/fuzionRed"
app:ms_arrowSize="16dp"
app:ms_baseColor="#color/fuzionRed"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelColor="#color/fuzionRed"
app:ms_floatingLabelText="#string/nicotineFloatingLabel"
app:ms_highlightColor="#color/fuzionRed"
app:ms_hintColor="#color/fuzionRed"
app:ms_multiline="false"
app:ms_hint="Nicotine"
app:ms_thickness="1dp" />
</LinearLayout>
<Button
android:id="#+id/homeDetailsActivityButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/fuzionRed"
android:text="Add To Cart"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="25sp"
android:textStyle="bold" />
</RelativeLayout>
change
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitCenter" />
to
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:adjustViewBounds="true"
android:scaleType="fitStart" />
I have a ScrollView with 1 RelativeLayout which has 3 sub RelativeLayouts:
I set top RelativeLayout to alignParentTop="true",
The bottom RelativeLayout to alignParentBottom="true".
The middle layout to
android:layout_below="#id/topLayout"
android:layout_above="#+id/bottomLayout"
Problem: Scrollview does not scroll when screen is small, instead topLayout stays at top and bottomLayout stays at the bottom. The middle layout gets small and (even lost) as like below:
Desired: I want topLayout stay at top and bottomLayout stay at bottom. But when there is no space there must be scroll so they middle layout must not get lost.
Code:
<?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="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context="com.jemshit.itu.fragments.TakeAttendanceFragment"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:paddingBottom="#dimen/halfClassic"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:paddingTop="#dimen/halfClassic">
<RelativeLayout
android:id="#+id/layoutWeekChoice"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="0dp"
android:background="#color/white"
android:layout_alignParentTop="true">
<Spinner
android:id="#+id/spinnerWeekChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/buttonSetDate"
android:layout_toStartOf="#+id/buttonSetDate"
/>
<Button
android:id="#+id/buttonSetDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:maxWidth="150dp"
android:textSize="16sp"
android:text="Set Date"
android:gravity="center"
android:textColor="#color/white"
android:textAllCaps="false"
android:background="#drawable/button_background"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:layout_alignBottom="#+id/spinnerWeekChoice"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutCardRead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:gravity="center"
android:layout_marginTop="32dp"
android:layout_below="#id/layoutWeekChoice"
android:layout_above="#+id/layoutShowAttendance"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageCard"
android:src="#drawable/std_card"
android:layout_alignParentTop="true"
android:layout_marginBottom="16dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/textWarningCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checking..."
android:textColor="#color/black"
android:textSize="14sp"
android:layout_below="#+id/imageCard"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutShowAttendance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/halfClassic"
android:background="#color/white"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/textAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attended: "
android:textColor="#color/black"
android:layout_alignParentTop="true"
android:textSize="16sp"/>
<TextView
android:id="#+id/textNotAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Attended: "
android:textColor="#color/black"
android:textSize="16sp"
android:layout_marginBottom="32dp"
android:layout_below="#+id/textAttended"/>
<Button
android:id="#+id/buttonManualAttendance"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="Manual Attendance"
android:gravity="center"
android:textAllCaps="false"
android:textSize="16sp"
android:textColor="#color/white"
android:background="#drawable/button_background"
android:minHeight="50dp"
android:layout_below="#id/textNotAttended"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Note: I do not want to use LinearLayout with weight="1" which will make my 3 layouts same height
EDIT: now ScollView scrolls with new code below but my bottom TextViews get lost:
Code Updated:
<?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="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context="com.jemshit.itu.fragments.TakeAttendanceFragment"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingBottom="#dimen/halfClassic"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:paddingTop="#dimen/halfClassic">
<RelativeLayout
android:id="#+id/layoutWeekChoice"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="0dp"
android:background="#color/white"
android:layout_alignParentTop="true">
<Spinner
android:id="#+id/spinnerWeekChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/buttonSetDate"
android:layout_toStartOf="#+id/buttonSetDate"
/>
<Button
android:id="#+id/buttonSetDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:maxWidth="150dp"
android:textSize="16sp"
android:text="Set Date"
android:gravity="center"
android:textColor="#color/white"
android:textAllCaps="false"
android:background="#drawable/button_background"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:layout_alignBottom="#+id/spinnerWeekChoice"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutCardRead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:gravity="center"
android:layout_marginTop="32dp"
android:layout_below="#id/layoutWeekChoice"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageCard"
android:src="#drawable/std_card"
android:layout_alignParentTop="true"
android:layout_marginBottom="16dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/textWarningCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checking..."
android:textColor="#color/black"
android:textSize="14sp"
android:layout_below="#+id/imageCard"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutShowAttendance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/halfClassic"
android:background="#color/white"
android:layout_below="#id/layoutCardRead"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/textAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attended: "
android:textColor="#color/black"
android:layout_above="#+id/textNotAttended"
android:textSize="16sp"/>
<TextView
android:id="#+id/textNotAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Attended: "
android:textColor="#color/black"
android:textSize="16sp"
android:layout_marginBottom="32dp"
android:layout_above="#+id/buttonManualAttendance" />
<Button
android:id="#+id/buttonManualAttendance"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="Manual Attendance"
android:gravity="center"
android:textAllCaps="false"
android:textSize="16sp"
android:textColor="#color/white"
android:background="#drawable/button_background"
android:minHeight="50dp"
android:layout_alignParentBottom="true"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Set your parents RelativeLayout height to wrap_content. Match_parent needs only ScrollView, everything inside it can spend all the space it needs.
From your 2nd relative layout,that is layoutcard remove android:layout_above="#+id/layoutShowAttendance"
and from layoutShowAttendance remove
android:layout_alignParentBottom="true"
and add android:layout_below="#+id/layoutCardRead" to layoutShowAttendance
It will work.