Why are the views not being elevated using android:elevation - android

I am trying to use the android:elevation attribute but it has no effect on the views. What I am doing wrong?
Here is the xml code with one FrameLayout and one Button but none of them is showing any shadow.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.vaibhav.uielements.MainActivity">
<FrameLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:elevation="15dp"
android:background="#android:color/white"
android:layout_centerHorizontal="true" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="10dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp"
android:id="#+id/button" />
</RelativeLayout>
[

Related

Make a ListView visible when the layout is set to have black background

I have a simple activity with a relative layout, ListView, and a TextView
I want to make my app have black background and white text, but when I set the background of Layout and TextView to black, the ListView isn't visible...
How can i overcome this problem. I want background to be black, but still have the ListView visible.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="#+id/txtOut"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="17sp"
android:textColor="#android:color/background_dark"
android:scrollbars="vertical"
android:isScrollContainer="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAlignment="center" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/songListView"
android:layout_below="#+id/txtIn" />
</RelativeLayout>
This was hard to explain, so I apologize for that, although i tried my best.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="#+id/txtOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:textColor="#android:color/background_dark"
android:scrollbars="vertical"
android:isScrollContainer="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAlignment="center" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/songListView"
android:layout_above="#+id/txtIn" />
</RelativeLayout>
try this hope it helps
Instead of setting everything to black, choose a dark theme.

Android-how to set image in particular layout starting center point?

I want to set like below image :
pls help me to solve out this layout..
Thanks in advance.
BASIC
CardView have higher elevation than ImageView. So just set higher
elevation for ImageView.
Here we go ..
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".activity.Splash"
tools:showIn="#layout/activity_splash"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
android:elevation="5dp"
android:stateListAnimator="#anim/button_elevation"
android:id="#+id/one"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
>
<RelativeLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin"
android:background="?attr/selectableItemBackground"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is just for test"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<ImageView
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cross"
android:id="#+id/two"
android:layout_centerVertical="true"
android:elevation="10dp"
/>
</RelativeLayout>
</RelativeLayout>
And the screen shot ....

Floating Action Button background graphic not showing (android)

I am attempting to put a FAB on a fragment. The problem is that the background graphic (it is a plus sign) is not showing up in the circle, it just looks like a solid circle of color at the bottom. Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:gravity="center_horizontal"
tools:context=".SMS2EmailActivity"
android:background="#drawable/backgroundgradient">
<include layout="#layout/contact_content" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#drawable/plus_circle"
android:tint="#color/tint"
app:elevation="4dp"/>
</android.support.design.widget.CoordinatorLayout>
and the included file:
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/backgroundgradient"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvInstructions"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add"
android:id="#+id/btnAdd"
android:layout_below="#id/tvInstructions"
/>
<LinearLayout
android:id="#+id/layoutEmailContactEXLVHeader"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="vertical"
android:layout_marginRight="0px"
android:layout_below="#id/btnAdd">
</LinearLayout>
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/elvEmailContact"
android:background="#ffffff"
android:cacheColorHint="#00000000"
android:fadeScrollbars="true"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbarStyle="insideInset"
android:layout_below="#+id/layoutEmailContactEXLVHeader"
android:scrollbarTrackVertical="#drawable/track"
android:divider="#color/black"
android:dividerHeight="1dp"
>
</ExpandableListView>
What am I doing wrong?
I needed to add:
android:src="#drawable/plus_circle
to the FAB layout.

When centering vertically, how to account for action bar?

I'm centering properly, as you can see when you look at the content_main.xml design tab,
However, when you look activity_main.xml design with the action bar in place, while it is still centred in the app, it is not centred within the whitespace, which is what I would prefer. Any suggestions on how to account for the action bar? Preferably in the XML if possible.
Here is my XML
<?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:id="#+id/voting_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:layout_gravity="fill_vertical|center"
android:configChanges="orientation|screenSize"
android:screenOrientation="nosensor"
tools:context="com.gesslar.threshvote.MainActivity"
android:background="#color/colorFaded"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main">
<TextView android:id="#+id/textStatusMessage"
android:textColor="#color/colorText"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
<ImageButton android:id="#+id/buttonVote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:src="#drawable/ic_vote_button_image"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:onClick="onVotePressed"
android:layout_gravity="center_horizontal|center_vertical"
android:adjustViewBounds="true"
android:contentDescription="#string/desc_vote_button" />
<TextSwitcher android:id="#+id/textCountdown"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:textColor="#color/colorText"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/countdown"
android:includeFontPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar android:id="#+id/loadingBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_gravity="end"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:indeterminate="true"/>
</LinearLayout>
That xml worked for me:
<?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:id="#+id/voting_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical|center"
android:background="#color/colorFaded"
android:configChanges="orientation|screenSize"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:screenOrientation="nosensor"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.gesslar.threshvote.MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:id="#+id/textStatusMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorText" />
<ImageButton
android:id="#+id/buttonVote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:background="#android:color/transparent"
android:clickable="false"
android:contentDescription="#string/desc_vote_button"
android:onClick="onVotePressed"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:scaleType="fitCenter"
android:src="#drawable/ic_vote_button_image" />
<TextSwitcher
android:id="#+id/textCountdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/buttonVote"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:includeFontPadding="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorText"
android:textSize="#dimen/countdown" />
<ProgressBar
android:id="#+id/loadingBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/textCountdown"
android:layout_gravity="end"
android:indeterminate="true"
android:visibility="invisible" />
</RelativeLayout>
But you need to run it on the device or emulator. Android Studio preview shows it wrong. The key line is app:layout_behavior="#string/appbar_scrolling_view_behavior"
EDIT
Also you need to use RelativeLayout - it supports good centering in parent. In LinearLayout you can center image only if your ImageView will be match_parent.

stick LinearLayour ( horizontal ) to the buttom without any space

Sorry, i've completed my question very much, so I reasked that and deleted prev post...
I'm using LinearLayout ( with 4 ImageButtons in a raw ) in a RelativeLayout in my project and I have used android:layout_alignParentBottom="true" for it ( linear ) to stick to the buttom of RelativeLayout, but my problem is the space between LinearLayout's ImageButtons and the corners of the screen. I want to remove them to make my ImageButtons be like a menu bar on the bottom of the screen. Is it possible for anyone to help me please ? THANK YOU ! :)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".HomeActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="TXT"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="4" >
<ImageButton
android:id="#+id/calibrate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/1" />
<ImageButton
android:id="#+id/chart"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/2" />
<ImageButton
android:id="#+id/guidance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/3" />
<ImageButton
android:id="#+id/info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable4" />
</LinearLayout>
</RelativeLayout>
and the result is something like this : Picture http://uploadtak.com/images/c6645_1311.png!
1
Remove the padding on your RelativeLAyout
From:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".HomeActivity">
To:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

Categories

Resources