TextView on Horizontal ScrollView in android? - android

Can you tell me when we select an item in GalleryView its comes to the center of the screen how to restrict it? I want to just be there where i click that item. How? Simple words, I wanna horizontal Listview. How?
Thanks

HI,
I would advise you check the "Hello, Gallery" on the google doc, it is very clear. Gallery is design to "display items in a horizontally scrolling list that locks the current selection at the center", as they say.
You just need to replace the ImageAdapter by TextAdapter, and put TextViews in it instead of ImageViews. It actually work exactly like a Listview. so you know how to do a Listview, this should be easy.
EDIT
Here is I think a nice solution :
You need to change the style of the gallery. As default it is defined like that :
<style name="Widget.Gallery">
<item name="android:fadingEdge">horizontal</item>
<item name="android:gravity">center_vertical</item>
<item name="android:spacing">-20px</item>
<item name="android:unselectedAlpha">0.85</item>
</style>
So you need to create your own styles.xml in your folder gallery and put that in it :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="gallery" parent="android:Widget.Gallery">
<item name="android:fadingEdge">horizontal</item>
<item name="android:gravity">center_vertical</item>
<item name="android:spacing">0px</item> <!--This gives you no spacing between elements -->
<item name="android:unselectedAlpha">1</item> <!--This puts all elements the same alpha -->
</style>
<resources>
This gives me this :
alt text http://img249.imageshack.us/img249/1893/testgallery.png
Now I'm sure we can get better result by playing with the various attributes of the gallery and the style, but I think this is a good lead for you ;)

Related

Customizing Up/Back/Burger background in my ActionBar

I'm trying to customize the background of my action bar items with a selector, to override what is shown when the button is pressed.
This was pretty easy with menu buttons (e.g., overflow icon), as you can style them with actionBarItemBackground .
Sadly this does not apply for the up/home/left indicator. I have unsuccessfully tried, in my styles.xml:
<item name="actionButtonStyle">;
<item name="actionBarStyle">;
<item name="toolbarStyle">;
None of the nested attributes seem to act on the home icon background. I also searched over android.R.attr and gave a look at this. Is there any way?
I would like to stay with the "up" indicator, without inflating a custom view. In that case, I would also have to inflate the title as well as custom views naturally appear at the end of the title. AND I would lose the burger-to-arrow animation, AND I would have to take care about margins and design guidelines (now managed by AppCompat), and some other bad thing on the way.
I thought about setting a Logo, but that would have some complications as well and I don't think I could change the background anyway.
I thought about Toolbar being a Layout, so I could put custom views in it from XML. If I'm not wrong they appear after the title, so neither this is a good idea.
What can I do?
please let me know if it works
add this to your your theme or if it doesn't take both remove the one with android prefix
<item name="android:selectableItemBackground">#drawable/selector</item>
<item name="selectableItemBackground">#drawable/selector</item>
Example #drawable/selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#ddffffff" />
<item
android:drawable="#android:color/transparent" />
</selector>

Compound drawable in a TextView is stretching beyond the image size

I am creating a menu in an Android app with several list items and corresponding icons. The problem that I'm having is that the icons are being stretched beyond the image size for some reason. I have created a menu like this before without such a problem, and I essentially copied the code over to this new project, primarily only changing the image names and string names.
Here is the code from the menu layout for a single list item:
<TextView
android:id="#+id/listItemCardTransactions"
style="#style/NavigationMenuItem"
android:drawableLeft="#drawable/ic_card_transaction_menu_icon_normal"
android:text="#string/card_transactions" />
Here is the NavigationMenuItem style:
<style name="NavigationMenuItem">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingTop">#dimen/menu_list_item_padding</item>
<item name="android:paddingBottom">#dimen/menu_list_item_padding</item>
<item name="android:paddingLeft">#dimen/menu_list_item_padding</item>
<item name="android:drawablePadding">#dimen/menu_list_item_left_padding</item>
<item name="android:gravity">center_vertical</item>
<item name="android:clickable">true</item>
<item name="android:background">#drawable/selector_navigation_item</item>
<item name="android:textSize">#dimen/text_size_menu_item</item>
</style>
Here are the dimensions:
<dimen name="text_size_menu_item">18sp</dimen>
<dimen name="menu_list_item_padding">6dip</dimen>
<dimen name="menu_list_item_left_padding">12dip</dimen>
And here is what the menu looks like right now (I know there are several other problems but those aren't my concern right now). You can see the stretching problem best when you drag-and-drop the image to get the full view:
And what the icon is supposed to look like (this one is grey since I wasn't sure how to easily make the white one visible on a white background):
Anyone know what might be causing the image to stretch past its dimensions like this?
I would follow Barry's advise in the comments, ie use an ImageView + TextView inside a LinearLayout for each item. However, to solve the "the height of the list item is smaller", you could try adding the following attribute to the ImageView:
android:adjustViewBounds="true"
If I'm not mistaken, this should effectively make sure that the view bounds is actually based on the content of the image, and not the aspect ratio (ie, it won't change the height beyond the maximum height of the image itself due to "scaling").
Hope that helps (and also makes a bit sense).

Customizing Android ScrollView's Vertical Scrollbar

I need to customize ScrollView so it will look like in the picture:
I already successfully customized the Thumb and the Track, but I don't know how to add Arrows like in the picture I provided.
Here is the style I'm using:
<!-- Scrollbar -->
<style name="scroll_view">
<item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fadeScrollbars">false</item>
<item name="android:scrollbarThumbVertical">#drawable/sb_thumb</item>
<item name="android:scrollbarTrackVertical">#drawable/sb_track_vertical_bg</item>
</style>
The Arrows should be a part of the ScrollView style to avoid extra spacing and also they need to be simple, non clickable and e.t.c.
If you want to add buttons for up and down, you can place two buttons above and below of Scrollview.And programatically scroll the scroll bar on button click.
For that purpose, you can use following code,
scrollview.scrollTo(5, 10);

Change font/typeface when button is pressed

I already how to change the style of an element with selector but I found nothing about the typeface...
Is it possible to do with ? Or is there another way?
Sadly, right now it is not possible.
There is a ticket for that in the Android code repo :
https://code.google.com/p/android/issues/detail?id=8941
Your best option is to manage it yourself in ontouch listeners (and yes this is ugly) or implement these new selectors yourself.
Typeface can easily be an element of your style... If you're using default android styles, then the idea would be to extend whatever style you're implementing and just change the elements you need. like the following style element, taken from the android styles and themes documentation:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="#android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
Then apply this style in your selector, just like you already know how to do.
The other option is, of course, to do it in code, but the selector is much cleaner
When button is clicked,Use below code to change font of the text(custom typeface).
Put your font under main->assets->fonts directory.
//change font when button pressed
val typeFace = Typeface.createFromAsset(activity!!.assets,"fonts/sf_semi_bold.ttf")
buttonAbout.setTypeface(typeFace)
TextView.setTypeFace() Use Ctrl+Space to show a giant list of classes for TextView or anything in general on.

Set color for expandable list

I just tried the current Google sample for ExpandableListiew: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html
This sample seem very simple and easy to use.
But what I would like to do is to say that change back ground color for child element and group element.
it doesn't uses any child_row.xml , group_row.xml.
please tell me the right way to do.
Thank a lot for any information.
you can define new style for the expandable list view like below...
<style name="Widget.MyExpandable" parent="android:Widget.ExpandableListView">
<item name="android:listSelector">#drawable/list_selector_background</item>
<item name="android:divider">#color/ex_listview_stroke</item>
<item name="android:cacheColorHint">#color/color_foreground</item>
<item name="android:dividerHeight">0.5dp</item>
</style>
in hear list_selector_background is the drawable selector file in which you can define several states for the EXList view like stander and pressed etc...,
and to have different background for the child and parent you need to create separate... drawable background file for childview.xml and parentview.xml

Categories

Resources