Just note, I did reference the creating a dash line issues here on SO and with various searches via Google... Anyway, the issue is just that. I am not able to draw dash lines via xml (Can with DashPathEffect but don't want to keep doing this). Here is the dash drawable I use (dash_line.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#color/whiteColor"
android:dashWidth="10dp"
android:width="10dp"
android:dashGap="4dp"/>
</shape>
Now, then the implementation in xml for the imageview:
<ImageView
android:id="#+id/dash_test"
android:layout_width="200dp"
android:layout_height="10dp"
android:background="#drawable/dash_line"/>
I am working with Android API 18. I even disable Hardware Acceleration in the manifest and even on the view itself by setting the layer type (both tried in xml and programmatically). I verified by taking the view, dashView.isHardwareAccelerated() and it is false. Any thoughts as to what I am missing?
Edit:
I can draw solid lines by the way so I know its not a layering issue.
Edit:
One work around is to use PathDashEffect. Although then you get into the issue of not being able to draw on top of images (which I would need to do). So... still would like an xml solution.
Try setting software as a layerType in your ImageView:
<ImageView
android:layerType="software"
...
/>
Related
My app has a ImageButton whose quality is too bad. The actual image dimensions are 4176*4176 (4176pixels) which looks completely fine when opened separately. But when I import this to android studio and assign it to a ImageButton, the quality of the image downgrades. I have been trying a number of ways to fix this but haven't succeeded yet. I'm completely new to Android Programming.I go to res/drawable then right click to create a new Image Asset and then specify the location which imports the png file.
Actual image:
Image inside studio:
Here is the code in activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:id="#+id/police"
android:layout_width="317dp"
android:layout_height="295dp"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:background="#drawable/custom_button"
/>
</LinearLayout>
Custom button code which calls the image:
<item
android:state_pressed="true"
android:drawable="#mipmap/pressed" />
<item
android:drawable="#mipmap/defaultt" />
</selector>
You are actually referencing the image like Launcher icon in /mipmap directory.
I suggest reducing the image size which you are only using it for ImageButton and placing it inside /drawable with the quality you want or maybe smaller than the current one instead of placing it inside /mipmap directory.
Also, I don’t actually see the reason of how scaleType helps in ImageButton. You may wanna remove that line too.
I'd start by reviewing density independent pixels on Android. This is a good blog that covers the concept: https://www.captechconsulting.com/blogs/understanding-density-independence-in-android
The main issue is that your image (which is very high res) is getting compressed to fit inside of the image button. Typically, you would want to include image assets for different densities via different drawable resource directories (e.g., drawable-hdpi, drawable-xhdpi, drawable-xxhdpi).
However, these days, you can use vector drawables, which will reduce the need for having multiple assets for each density bucket, assuming you have the ability to generate SVG asset files: https://developer.android.com/guide/topics/graphics/vector-drawable-resources
Pinterest Style of Displaying Images is exceptional, and this adds beauty to your app. After a couple of research I found out that there are great libraries out there that can display images like Pinterest do but not sure if this is compatible with UIL.
I am using the Universal-Image-Loader in displaying my images. In the image shown below I got my images displayed in that manner with some views together with it. It is undeniably true that UIL library handles phone memory greatly in displaying a lot the images. I'd like to know if it is possible to display my images like the Pinterest's but still using UIL as the generator. What are the possible resolve to this approach? Or maybe another library that only handles the display and compatible with UIL.
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:horizontalSpacing="4dip"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="4dip"
android:padding="4dip" />
Update:
I tried using the StaggeredGridView but the layout can't be cast to GridView.
<com.origamilabs.library.views.StaggeredGridView
xmlns:tools="http://schemas.android.com/tools"
xmlns:staggered="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
staggered:numColumns="3"
staggered:drawSelectorOnTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Hey Check out my implementation of Pinterest type view using Staggered GridView and Universal-Image-Loader here.
I posted a question here before: Good way to make a launcher screen for sub-apps within your app?, and then started working on other parts of the app, and now I'm back to the same thing.
I want to make a nice screen with icons that the user can press, with room for more icons at a later date. Or maybe something different, I'm not sure.
Here's a current screenshot of what it looks like:
It looks pretty bad there, on my phone it looks better, with less space between the apps (this is a friend's phone), but ideally I want it to look good on all devices.
My XML code for this is as follows:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="20dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#FF6699FF"
/>
Any tips/suggestions are appreciated, I want to make this look good.
I'm not sure what format to store the icons in, right now they're just large (400x400 or so) png files.
If your icons are just squares you might want to use a compressed format like jpg or gif to reduce your app's file size.
I want to create a scrolling counter that rises at a rate I give it for an Android app, I feel like there is no Android widget that does this well in the SDK and I wanted some idea how this should be accomplished, or even better an open source project around this idea.
Picture example:
This might not be a perfect answer, but at least a starting point. Discounting the animation and general fanciness, you can get most of the way there just by decorating a TextView with some fancy XML. I'll share what I did a few years ago to make a similar-looking screen area for a tip calculator:
Here's the XML. Each single digit is one TextView so you can change them individually. I'm showing two here but obviously there were 5 for the screenshot below.
<TextView
android:id="#+id/tv1"
android:layout_width="60dip"
android:layout_height="140dip"
android:background="#drawable/gradient"
android:textSize="64sp"
android:gravity="center"
android:typeface="serif"
android:textColor="#FFFFFF"
/>
<TextView
android:id="#+id/tv2"
android:layout_width="60dip"
android:layout_height="140dip"
android:background="#drawable/gradient"
android:textSize="64sp"
android:gravity="center"
android:typeface="serif"
android:textColor="#FFFFFF"
/>
And the "drawable/gradient" I created as a separate drawable file:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dip"
android:color="#fbbb"
/>
<solid android:color="#600000"/>
<layout_margin android:layout_margin="1dip"/>
<gradient
android:startColor="#000000"
android:centerColor="#6D6D6D"
android:endColor="#000000"
android:angle="270"
/>
Here's the final result (inside a linearlayout):
In Addition to raggedToad's answer: You can use the ViewAnimator class to add animations to your counter. Its easy to use. You can extend it, add all the digit textviews in onCreate(). Implement a method increment that handles the increment operation. Just call showNext to flip to the next view.
I'm pretty sure that this particular counter in your screenshot has some short animations (about 5 or 10 frames) for each transition from one number to the next. Maybe there are also some more for showing rapid transitions without actually stopping at the particular number with more blurring.
So the main task would be creating the graphics. Then it's just a matter of displaying the right frame at the right time.
There's an open source project that does the exact thing you are trying to do.
Check: http://code.google.com/p/android-wheel/
I've done this before...not sure what i'm doing wrong now I know it's the simplest thing in the world but i just want to make the text of my settings page black and the background white. Any ideas of what i'm doing wrong? my code does nothing.
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FFFFFF">
<CheckBoxPreference
android:summary="summary goes here"
android:title="Preference 1"
android:defaultValue="false"
android:key="one"
android:textColor="#000000">
</CheckBoxPreference>
</PreferenceScreen>
FYI, I've tried #AARRGGBB it doesn't change anything. If i use the exact same android:background="#FFFFFF" in any layout file it works great. I just don't know why it's not working here :/
As I understand there is no way to change the look and feel of a preference activity.
I just wrote the whole thing again just to have a custom UI and to show a text beyond the settings in one of my apps.
Some people recommend to add another theme to the preference activity in the manifest. You could try it with the light theme of Android first. That should be:
android:theme="#android:style/Theme.Light"