Creating a layout over content background - android

My question is simple is a UI/UX design question. I want to get this model for my layout
I have no idea how is this called, want some help and idea for coding this one I tried few options but nothing.

To create this above layout You can use either of FrameLayout or Co-ordinator Layout or the new ConstraintLayout.
This will do it for you.
Refer this link to understand the above design.
<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="xyz.himanshusingh.cryptokoin.ui.display.MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#drawable/toolbargradient" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_below="#+id/toolbar"
android:background="#drawable/toolbargradient" />
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="80dp"
app:cardCornerRadius="10dp">
</android.support.v7.widget.CardView>
</RelativeLayout>
and toolbargradient.xml,
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="linear"
android:startColor="#f7792e"
android:endColor="#ef246b"
android:angle="180"/>
</shape>
This XML code will almost make the design for you. In place of CardView you can use whatever you want.Like a RecyclerView, DatePicker etc.
Hope this helps :)

Try using a Relative Layout for the image & recycler view and put the recycler view in cardview. This should work for 1st & 2nd view & in 3rd inside a cardview add a calendar & a recycler view below it. Hope this helps

Related

Adding a border to a Google PlaceAutocompleteFragment

I am using a Google Places Autocomplete fragment in an Android app. When I use the fragment directly in the top level of a LinearLayout, everything works:
<LinearLayout ...>
<fragment
android:id="#+id/findRidePlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"/>
</LinearLayout>
This layout leads to this UI:
As you can see, there is no border around the widget, whereas the TextView below it has a black border. From what I read, one trick to get a border around a fragment is to embed that fragment within a CardView. This method is actually recommended by Google's official documentation. Consider the following modified layout:
<LinearLayout ...>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_border">
<fragment
android:id="#+id/findRidePlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"/>
</android.support.v7.widget.CardView>
</LinearLayout>
The trick here is to give the CardView a background with the Google Places fragment above it, such that the former will appear as a border around the latter.
But this modified layout causes the app to crash. Does anyone know why this is crashing, or how I might place a border around a Google PlaceAutocompleteFragment ?
You can set a custom background for the enclosing LinearLayout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/main_border">
<fragment
android:id="#+id/findRidePlaceAutocompleteFragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
I'm using the same android:background="#drawable/main_border" that you have defined for your CardView. In my case main_border.xml (which lives on the res/drawable folder) looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#000000"/>
</shape>

How can I add a shadow to bottom sheet view?

As of now, with the official bottom sheet component from the Android design library implemented the top edge doesn't show a shadow. But for what I've seen in various mockups and in the Material Design specs, the bottom sheet include a discrete shadow of some sort.
I think the shadow would help distant the bottom sheet from the main layout, especially if there's a peek value set and/or the bottom sheet is always visible. Otherwise it just will blend together with the main layout and its items.
I've tried both ViewCompat.setElevation(bottomSheet, 5); and setting android:elevation="5dp" to the view in the XML, without success.
I know that a shadow shape doesn't have the same appearance as an elevation - but at least give it a try. The trick is to use app:layout_anchor to clip the shadow to the bottom sheet.
activity_main.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<View
android:id="#+id/shadow"
android:layout_width="match_parent"
android:layout_height="16dp"
android:background="#drawable/shape_gradient_top_shadow"
app:layout_anchor="#id/bottom_sheet" />
<FrameLayout
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="200dp"
android:clipToPadding="false"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior" />
</android.support.design.widget.CoordinatorLayout>
shape_gradient_top_shadow.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="#android:color/transparent"
android:startColor="#64000000"/>
</shape>
Looks like this:
EDIT
Get an even better result with a custom ShadowView:
Post from Roman Nurik on this topic: https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf
Gist of the ShadowView based on Roman Nurik's solution: https://gist.github.com/MariusBoepple/bf869e02541cd4750550e88fa07b5ddd
Then you can do the following:
<ShadowView
android:id="#+id/shadow"
android:layout_width="match_parent"
android:layout_height="16dp"
android:gravity="bottom"
app:layout_anchor="#id/bottom_sheet" />
For API Level 21 and higher, set the following in the parent view. You can also try in the rootview of the bottomsheet (I have not tried it in the root view)
android:background="#android:color/white"
android:elevation="16dp"
If no background then can use
android:outlineProvider="bounds"
For example, I have my sheet inside a nested scroll view
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:elevation="16dp"
android:outlineProvider="bounds"
>
<include layout="#layout/bottomsheet_1" />
</android.support.v4.widget.NestedScrollView>
The trick is to use a CardView as parent and set the elevation in the CardView
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:background="#fff"
android:clickable="true"
android:focusable="true"
app:behavior_hideable="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_height="140dp"
app:cardElevation="8sp"
card_view:cardCornerRadius="0dp">
<!--The content of your Bottom sheet-->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.
.
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
EDIT
This technique is not the best solution if you are supporting Kitkat and below. It's due to the extra margin added by the Cardview.
I think this will help you
first create bottom sheet like bellow then include in your main activity
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="56dp"
android:layout_marginTop="0.5dp" // this margin depend on shadow area
android:background="set you color"
android:elevation="20dp" // chose your custom elevation
app:layout_behavior="#string/bottom_sheet_behavior">
<LinearLayout
android:layout_marginTop="1dp" // this margin depend on max elevation
android:layout_width="match_parent"
android:layout_height="200dp">
</LinearLayout>
</LinearLayout>

Drop shadow renders without transparency

In this project (feature/drop-shadow branch) I am trying to add a drop shadow above a view container. Therefore, I defined the following shape (drawable/shadow_above):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#20000000"
android:endColor="#android:color/transparent"
android:angle="90">
</gradient>
</shape>
This is then used in the layout file (container_infos.xml) as follows:
<View
android:background="#drawable/shadow_above"
android:layout_width="match_parent"
android:layout_height="4dp"/>
The screenshot shows the result. For some reason the drop shadow looks awful. There is no transparency. What am I doing wrong? Feel free to send a pull request to my open source project.
Solution using a RelativeLayout
I managed to get the desired result by using a RelativeLayout in fragment_map.xml:
<?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:orientation="vertical"
tools:context=".ui.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<FrameLayout
android:id="#+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="#android:color/holo_purple"/>
<View
android:background="#drawable/shadow_above"
android:layout_alignBottom="#id/map_container"
android:layout_width="match_parent"
android:layout_height="4dp"/>
</RelativeLayout>
<include
layout="#layout/container_infos"/>
</LinearLayout>
There might be room for optimization.
as far as I see you should give map_container_infos_layout a negative top margin of the size 4dp and it should look better

android how to code dialog layout

I want to code this dialog layout: http://fooh.pl/pokaz/348687655.png
Green containner is in orange container. At the top of the dialogue is TextView. In the upper right corner is a button.
I know the types of layouts, but I failed.
Can anyone help me? Please.
Here you go:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rounded_orange">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:text="Text"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="32dp"
android:background="#drawable/rounded_green">
</RelativeLayout>
</RelativeLayout>
Where the drawables (only green shown here) are laid out like this:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#0F0"/>
<corners android:radius="16dp"/>
</shape>
If you need help applying the custom layout.xml file to your dialog, read up on 'Creating a Custom Dialog' in the official docs of Dialog.
Here's a link to the documentation with good examples or how to create a dialog fragment based on a layout.
And here is a good SO answer that shows how to inflate a layout for use in a dialog fragment.

Issue with sherlock actionbar

Image as seen in ICS
Where as when run in Gingerbread
XML code for the fragment
<?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"
android:orientation="vertical"
android:background="#drawable/background"
android:id="#+id/homelayout" >
<ImageView
android:id="#+id/homepageLogo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/background"
android:alpha="255"
android:scaleType="fitXY" />
</LinearLayout>
Any reason for such strange behavior?
try changing
android:layout_width="match_parent"
android:layout_height="match_parent"
to
android:layout_width="wrap_content"
android:layout_height="wrap_content"
in your ImageView. I don't know how you use your XML, but by the looks of it you might also want to change te same parameters in the LinearLayout to "wrap_content". Now you are telling the ImageView to (probably) fill the whole area.
// Alex
The problem is observed only when you dynamically request for the actionbar from the code.
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
If you do it using styles, this problem is not seen.

Categories

Resources