Remove margin of ListView contained in an ActionBarActivity - android

So I did an Activity that extends the ListActivity, and it worked fine, but then I found out that to make it work in old mobiles, it should extend ActionBarActivity instead, and when I turned it into that, theres a big margin surrounding my ListView. Thanks

For the old mobiles, I think you can import android.support.v7.app.ActionBar and give it a try. For more details, head to https://developer.android.com/guide/topics/ui/actionbar.html Thanks.

I found the problem was being caused by the following properties in the main.xml layout:
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
So removing them fixed the problem, I assume the default margin must be 0dp.

Related

Fade out last few lines of a TextView

I've been researching all over, I was unable to find a proper answer.
I also can't achieve this on my own, so please help me out
I have a InfoWindowDialog view I'm creating, which has a TextView, that has a certain maxHeight.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/txt_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LONG_TEXT_WHICH_HAS_A_FEW_LINES..."
android:maxHeight="50dp"/>
</RelativeLayout>
And I want to achieve something similar to the last few lines of this example:
I have tried a solution mentioned Fade bottom of a textview android
By placing android:requiresFadingEdge="vertical" and android:fadingEdgeLength="32dp" and had no results.
There are a few solutions to this. The easiest is to add an UI element. Add an overlay graphic at the bottom of your view that has some sort of transparency, e.g. 50%. This will achieve what you are asking.
Others options to consider:
1) Track the last line of text, break it up, and add 50% transparency to it.
2) Track the last line of text, break it up, and change the color to a different gray. This gives the impression of transparency
3) If using scrollview, they have fading edge features.
<ScrollView android:requiresFadingEdge="vertical">
and in your code, you can do the following
ScrollView scroll = findById(); scroll.setFadingEdgeLength(150);
OR in your XML use android:fadingEdgeLength="150dp". Cheers!

RelativeLayout Background isn't properly aligned

I'm trying to set up a background for my MainActivity in Android Studio, but it doesn't align properly on the top.
I've tried changing the device from Nexus 6P to Nexus 5 and Nexus 4 but it always looks the same.
This picture may help you understand the problem:
As you can see the gray triangle should be aligned at the top but there is a white line in the middle that I don't know how to remove.
This is my code, I'd really appreciate some help to fix this problem.
<?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:background="#drawable/background"
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="dancam.com.myapp.MainActivity">
</RelativeLayout>
I've tried also to set the android:layout_height to fill_parent but nothing changed
The theme that I'm using is Light_NoTitleBar
The Image I was using had a transparent gap above the gray triangle that caused the problem.
When I opened the image in android studio I was able to see the gap. Make sure you crop your images the right way!

Unable to use layout_gravity for ListView inside DrawerLayout

I am trying to add a Navigation Drawer inside my app. Here's the code:
<DrawerLayout 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"
tools:context="com.example.abcxyz.properprojectdb.MyDrawerActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
<ListView
android:layout_width="240dp"
android:layout_height="match_parent"
android:id="#+id/listView"
android:entries="#array/planets"></ListView>
</DrawerLayout>
I am unable to add the attribute android:layout_gravity for ListView. I don't know why it is not available for use (intellisense works perfectly, but it won't show layout_gravity)
My app crashes when I run it, but if I replace DrawerLayout with LinearLayout, the app doesn't crash.
I am guessing that it is because I have not added the attribute android:layout_gravity for ListView.
Here's a snapshot to show that layout_gravity doe not appear in intellisense either
I had the same issue and I wasted maybe 2 hours to find a solution. I tried restarting the IDE, invalidating, downgrading from 23 to 22, nothing worked.
Eventually, I HARD TYPEd it and it became available after I finished typing
android:layout_gravity=
(Worth mentioning I was on AS 2.1 ... maybe there was a weird bug)
Replace:
DrawerLayout
with
android.support.v4.widget.DrawerLayout
and add following line to your build.gradle:
compile "com.android.support:support-v4:22.0.0"
UPDATE
DrawerLayout should consist of 2 views and it seems that you cannot set layout_gravity to the view which represents drawer itself. You can always wrap your ListView in other layout and then set layout_gravity on your ListView.
Every things seem to be no problem. You can put android:layout_gravity="start" or android:layout_gravity="end" in ListView
UPDATE
I saw my bad. #questioner was right. Your must change DrawerLayout to android.support.v4.widget.DrawerLayout

Change the view background when an item from a ListView is activated/selected

I'm going to explain (or at least try that) what I want to achieve because this is driving me crazy.
I have a ListView and the items have the following layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/item_background"
android:duplicateParentState="true" >
... some contents here...
</FrameLayout>
</FrameLayout>
"item_background.xml" contains a selector so the background changes depending on the item's state. It's working fine when I press and release the item but it's not working when I 'select' the item with a DPAD/Trackball. I have tried everything (state_activated, state_focused, state_selected...) but nothing works. I'm trying to search for a solution but looks like I can't find the proper keywords to search for.
Any ideas?
Thank you!
Finally I fixed it. The problem was in the order I put the items inside the selector (I put a state_pressed="false" before the state_selected="true").
Now it works flawlessly.
Thank you everyone for your help.
This does most likely not work because some layout above your root layout gets the focus (hard to tell without the rest of the layout).

Finding custom Preference's view padding that works for all versions of android

I have a PreferenceActivity containing a custom seekbar that extends the Preference class and it works properly, however I can't seem to find out how to set the margins (or padding) to have the view look the same on 2.3.3-2.3.7 and 4.0+ (the versions our apps target).
Here is the layout I use for the view of the preference:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="5dp"
android:paddingBottom="5dp">
That layout makes the view look good on anything 4.0 and above, but when ran on 2.3.3-2.3.7, the view seems to have extra padding to the left.
Is there a way to find out the proper left/right padding a custom Preference should have to look similar in appearance to other preference views, preferably without having to provide version-specific padding?
Thanks!

Categories

Resources