Tag: android-layout

RelativeLayout not properly updating width of custom view

I have this container class that is used to make one of the dimensions, either the width or height, a ratio of the other dimension. For instance, I want a 16:9 layout container where the width is “match_parent”. However, when using the height as “match_parent”, Android does not seem to properly relayout itself. When I […]

Skin Options Menu Android

I’m trying to skin the options menu on android. I have the background color changed with a custom theme, but I can’t get the text color to change for some reason. My Theme <style name=”default” parent=”@android:style/Theme.NoTitleBar”> <!– Menu panel colors –> <item name=”android:panelBackground”>@color/optionsMenuBackgroundColor</item> <item name=”android:panelFullBackground”>@color/optionsMenuBackgroundColor</item> <!– Menu item colors –> <item name=”android:itemTextAppearance”>@style/OptionsMenuFont</item> </style> My Style […]

Marshmallow RelativeLayout behaves strange with alignBaseline

On Android 6.0 Marshmallow the positioning of an EditText in relation to an ImageView in a RelativeLayout with the attributes baseline and layout_alignBaseline does not work anymore. The behaviour can even be observed in the layout editor in Android studio. On a real Android Marshmallow device or emulatr the EditText in my case is shift […]

Why setWidth does not work?

For example, for a TextView in Android you have to set the LayoutParams instead of the setWidth method. TextView tv = new TextView(getContext()); LayoutParams params = new LayoutParams(100, LayoutParams.WRAP_CONTENT); tv.setLayoutParams(params); But why? In the Android docs it says it would deliver the same result.

How do I alignBaseline to bottom line of multi-line TextView?

I have two TextViews side by side. Let’s say the left TextView is 1 line and the right TextView is 2 lines. Is there any way to align the baselines of the left TextView with the last line in the right TextView? I’m open to using whatever layout (RelativeLayout, LinearLayout, etc.) that can accomplish this. […]

How to find the Text Area(Height/Width) of TextView programmatically in android

I have an EditText, a Button and a TextView. On clicking the button, textview shows the text written in edittext. Is it possible to find the size of textview occupied depending upon text. i.e. If It has three characters “abc“, what is width now, if it has 5 characters like “abcde” , then what is […]

RecyclerView: find last visible item immediately after view created

I’m having a problem with the following methods: int firstVisibleItemPosition = gridLayoutManager.findFirstVisibleItemPosition(); int lastVisibleItemPosition = gridLayoutManager.findLastVisibleItemPosition(); My goal: save analytic data about what items the user have viewed. In order to do that, I’m calling this methods in two different scenarios: every time scrolling turned to “idle” state, and checking what are the visible items. […]

TextView lineSpacingMultiplier less than zero chops last line

I have a TextView where I want the line spacing to be less than 1.0, i.e. there will be less than the default amount of space between lines. I’ve done this: <TextView android:id=”@+id/text_header” android:layout_width=”@dimen/text_header_width” android:layout_height=”wrap_content” android:text=”@string/header_text” android:textSize=”@dimen/text_header_text_size” android:typeface=”helvetica” android:lineSpacingMultiplier=”0.95″ /> But in the text on the bottom line, the descenders (e.g. y’s, g’s, and p’s) […]

Having vertically scrolling pages in ViewPager

This may be obvious and a completely unneeded post but I had been having quite an issue resolving a way to allow vertical scrolling functionality on pages in a VewPager and there were very few resolutions coming across google and even here. I found some claiming to resolve the issue but they seemed to be […]

Image resolution for mdpi, hdpi, xhdpi and xxhdpi

I have a background for my app in resolutions 720×1280 pixels, 1080×1920 pixels and 1440×2560 pixels. In which folders (mdpi, hdpi, xhdpi and xxhdpi) should I put each background?

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.