I have been toying with a few different libraries and code snippets for the past few days. I am trying to create a menu like the one seen in the facebook app.
Now there are many libraries and resources on building something of that kind, but I'm having major difficulties in drawing a shadow between the 'top' and 'bottom' page as to create the illusion that the 'top' page is actually on top.
Now the exact effect Im trying to create is displayed in this article:
http://android.cyrilmottier.com/?p=717
The author of the article I got this from is not very thorough in his explanation. This could be due to my programming-skills-under-development, or maybe I'm not the only one.
I'm using the following library and example app to test and develop with:
https://github.com/jfeinstein10/SlidingMenu
I would be very happy if anyone could help me get this to work.
PS: I'm very sorry, but since I'm a newbie here I am not allowed to post any pictures.
What I did is I'm putting a shadow at the right of my menu view (ie behindView) with a margin on the right of your above view :
<!-- Show shadow on the right of the menu -->
<RelativeLayout
android:id="#+id/menuShadow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="false"
android:clickable="false"
android:background="#00000000"
android:layout_marginRight="40dp">
<ImageView
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_width="6dp"
android:layout_height="fill_parent"
android:background="#layout/border_menu_progressive_shadow"/>
</RelativeLayout>
With my shadow layout:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#00101010"
android:endColor="#252525"
android:angle="0" />
</shape>
</item>
</selector>
Related
Here's the XAML that I am using for a startup screen:
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<item android:drawable="#android:color/black"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test"
android:gravity="center"
android:layout_gravity="center"
android:textSize="40sp"
android:textStyle="bold"
android:fontFamily="sans-serif-medium"
android:textColor="#fff"
/>
</layer-list>
I was hoping to see white text centered on a black screen. The screen is black, but instead I cannot see any text appear at all.
I understand what you are trying to do.
You want to display a plain Text on your "Splash Screen" that displays when you open an app. Since you are using Xamarin, you have access to all the native API's and you can do everything that native developers can.
Unfortunately, being able to show plain text on the splash screen is not possible in native development. Android restricted it because "the view comes from the theme. When you set up the UI for your splash activity in the theme, it is available immediately".
Why can't I have plain text on the splash screen, when I can have images? As you see over here in detail, the splash screen only accepts drawable resources. And there is no way to convert plain text into XML drawable resources.
You do have another option though. You can use a "Loading screen". You can make the app show the splash screen, then a Loading screen, and then load the right page. Let me know if that makes sense
Set background attribute to black. Either
android:background="#000"
or
android:background="#android:color/black"
I'm not used to Xamarin in specific, but if you normally want to create some sort of splash screen for your activity, as far as I know, there is no way of directly adding a TextView to it, because LayerList only supports bitmaps (image drawables) as child items. So you would have to create an .img file containing your text. Then, you can add the image with the text to the layer-list like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This line below is for the background colour -->
<item android:drawable="#000" />
<item>
<!-- The bitmap below contains the image with the text -->
<bitmap
android:src="#drawable/my_text_on_screen"
android:gravity="center" />
</item>
</layer-list>
To see how to create an image from a text, have a look at this StackOverflow question.
Let me know of this is what you wanted to achieve! I hope this helps.
I have some problems using the new CardView
That's my current situation: I want to use a CardView to provide a Floating Action Button for all devices (also Pre-Lollipop)
my activity's layout looks like this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cdcdcd"
android:focusable="false">
<include layout="#layout/toolbar"/>
<android.support.v7.widget.CardView
android:layout_width="58dp"
android:layout_height="58dp"
cardview:cardPreventCornerOverlap="true"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="18dp"
cardview:cardCornerRadius="29dp"
cardview:cardBackgroundColor="?attr/colorPrimary">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:layout_margin="12dp"
android:src="#android:drawable/ic_menu_edit"/>
</android.support.v7.widget.CardView>
Running the app on a Nexus 5 (4.4.4) the screen looks like this:
now I want to set the cardElevation by setting this in the xml
cardview:cardElevation="8dp"
After starting the app the button looks like this (it isn't a circle anymore):
It seems setting the card elevation also affects the view's dimensions... If you take now a closer look to picture #1 you can see, that this button isn't also a perfect circle.
Is there a way to figure that out? I also tried to set this
cardview:cardPreventCornerOverlap="false"
But it also has no affect
Thanks guys :)
Using CardView for FAB shadows is not the best idea. CardView is a layout, so it's pretty heavy. It's also very limited on pre-Lollipop versions. The shadow is not animated, corners pad the content and there's no ripple. Seems like there's no good method to achieve 100% FABs using only AppCompat.
In general I'm not happy being limited to AppCompat, so I wrote my own Button classes based on regular ones. I was able to achieve pretty good results as you can see on the screenshot. It's Gingerbread and there are animated shadows, ripples, vector graphics, etc. It's a pretty large repository, so I'm unable to give you a short solution here, but if you wish, check out the code on github.
You could try using the FAB from this MaterialDesign library if you're desperate for the shadow effect on older devices.
You can find the library at https://github.com/navasmdc/MaterialDesignLibrary
<com.gc.materialdesign.views.ButtonFloat
android:id="#+id/buttonFloat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="24dp"
android:background="#1E88E5"
materialdesign:animate="true"
materialdesign:iconDrawable="#drawable/ic_action_new" />
Alternatively you could create your own shadow resource in your drawables folder, and add the shape below your button, something like this:
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/black_alpha"/>
<corners android:radius="20dip"/>
And create a layer list resource where you include your button and the shadow
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/shadow"/>
<item
android:drawable="#drawable/button"
android:bottom="4px" />
</layer-list>
I wish to achieve something similar to the following:
Notice how the image pattern to the right of the triangle repeats until it hits the edge of the screen. Also, the triangle will not actually be a triangle (i.e. the image will not be a simple shape) so please be aware of that.
I'm quite new to Android and know that in iOS it is possible to set a portion of the image to repeat. I'm not sure if this is true also of android and if so how? If not, then what would be the recommended approach?
To repeat an image you may set the TileMode for this Bitmap. To move it in your case to the right you may define a layer-list drawable and give its item a left property:
tile_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<bitmap android:src="#drawable/tile_start" android:gravity="left|bottom"/>
</item>
<item android:left="60px">
<bitmap android:src="#drawable/tile" android:tileMode="repeat"/>
</item>
</layer-list>
just some layout:
<?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" >
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:background="#drawable/tiled_background" />
</LinearLayout>
If I understand correctly you may want to take a look at NinePatch images http://developer.android.com/reference/android/graphics/NinePatch.html
Nine Patch images are "smart" in the sense they can have certain bounds that can be stretched and repeated as necessary. Here's a quick tool that can give a better idea of it, http://romannurik.github.io/AndroidAssetStudio/nine-patches.html
I have a horizontal ProgressBar that works great.
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_marginBottom="5dp"
android:background="#drawable/progress_radial_background"
android:progressDrawable="#drawable/custom_progress_bar" />
I do this:
pb.setMax(100);
pb.set(point);
And it shows the status of a user's level. When it fills all the way, they reach a new level and it starts over. It will only move/increase when the user do some action to increase points.
However, I'd like to make this circular instead of horizontal. But when I do, it wont stop the spinning animation (like a loading animation). Can I make the circular ProgressBar the same way?
Custom Progress Bar code in my Drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#android:id/background"
android:drawable="#drawable/list_press">
<corners android:radius="6dp" />
</item>
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/progress_bar_green" />
</item>
</layer-list>
There is no standard Android widget that does what you want.
However you could use this library that does it: https://github.com/Todd-Davies/ProgressWheel.
This poster seems to have found an answer.
It seems like they took the android drawables for the circular progress bar and filling, specified in xml layout that it was a horizontal progress bar and made it determinate.
Please take a look to this GitHub library called RefreshActionItem, I think it is exactly what you are looking for:
https://github.com/ManuelPeinado/RefreshActionItem?source=cc
You have as well this one for another idea or just check it out:
https://github.com/f2prateek/progressbutton?source=c
I'm trying to create an icon/widget (1 cell x 1 cell) that can be placed on the home screen of android. The widget will look and act exactly like the other standard shortcuts in android. It will have an icon and under that a label, it will be selectable with the trackball (highlight able) it will be highlighted when it is selected/clicked.
How do I go about creating this home screen widget?
Do I have to create the widget myself using code/xml or is there some standard xml, style, theme, code that I can use to ensure that the widget will have the same style/theme as the other home screen widgets?
I currently have the following
res/drawable/corners.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Corners">
<stroke android:width="4dp" android:color="#CC222222" />
<padding android:left="4dp" android:top="1dp" android:right="4dp" android:bottom="1dp" />
<corners android:radius="4dp" />
</shape>
res/layout/widget.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Widget"
android:layout_width="72dip"
android:layout_height="72dip"
android:orientation="vertical"
android:focusable="true"
android:gravity="center_horizontal"
style="#android:style/Widget"
>
<ImageView
android:id="#+id/WidgetIcon"
android:src="#drawable/icon"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:paddingTop="3dip"
android:gravity="center"
/>
<TextView
android:id="#+id/WidgetLabel"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/app_name"
android:textSize="15dip"
android:background="#drawable/corners"
/>
</LinearLayout>
The resulting widget looks some what close, but its not selectable, it doesn't get highlighted when clicked and the label isn't exactly in the correct location or the correct style.
Any ideas, if there is a correct way to do this, or should I just keep working away on the above until I am closer?
The "correct way to do this" is to make a shortcut, and not try to mimic it with an app widget. This has been pointed out repeatedly by the core Android team (notably Romain Guy) on the [android-developers] discussion list, such as:
Widgets should look like widgets, not
like shortcuts. The main reason is
that there is absolutely NO guarantee
about what a shortcut will look like.
Other devices (especially ones with
custom system UIs like MOTOBLUR or HTC
Sense) might have a different look and
feel. Or in the next update of Android
we might change the way shortcuts are
presented.
To make your item consistent with the system look and feel is not hard by referencing the system attribute android:attr/selectableItemBackground. For example, if you want to make an ImageView in your widget look "selectable" with proper highlighting etc: just do
<ImageView
...
android:background="?android:attr/selectableItemBackground"
...
/>
There are a lot in android_sdk_path/platforms/android-x. Happy digging!
EDIT: I found out later that this simple attribute does not live in SDK < v11. So the best way I know now is to download the appwidget template pack and use it.