How to set foreground attribute to other non FrameLayout view

The idea is to surround your layout with a FrameLayout, and set the selector and the onClick event to this layout. <FrameLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/selectableItem” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:foreground=”@drawable/foreground_row” > <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/cardContent” android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”@drawable/row_background”> … </RelativeLayout> </FrameLayout> You can find a full explanation at my blog: http://antonioleiva.com/unveiling-bandhook-foreground-any-layout/ Or you can extend rhis FRelativeLayout https://gist.github.com/shakalaca/6199283

ClassCastException android.widget.FrameLayout$LayoutParams to android.support.v4.widget.DrawerLayout$LayoutParams

What solved this issue for me: In MainActivity, add a new field for the LinearLayout, and assign value to it in onCreate() (this part just like emaleavil suggested): private LinearLayout linearLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // … linearLayout = (LinearLayout) findViewById(R.id.linearLayout); } Then in selectItem(), when calling closeDrawer(), simply pass linearLayout as … Read more

Android YouTubePlayer with unauthorized overlay on top of player

I faced the same problem today, and for me the error in the logs was: W/YouTubeAndroidPlayerAPI﹕ YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor com.google.android.youtube.player.YouTubePlayerView{42686bc8 V.E….. …….. 0,0-1200,675 #7f0a00a0 app:id/video_player}. The distances between the ancestor’s edges and that of the YouTubePlayerView is: left: … Read more

Full screen background image in an activity

There are several ways you can do it. Option 1: Create different perfect images for different dpi and place them in related drawable folder. Then set android:background=”https://stackoverflow.com/questions/16135984/@drawable/your_image” Option 2: Add a single large image. Use FrameLayout. As a first child add an ImageView. Set the following in your ImageView. android:src=”https://stackoverflow.com/questions/16135984/@drawable/your_image” android:scaleType = “centerCrop”

What are the differences between LinearLayout, RelativeLayout, and AbsoluteLayout?

LinearLayout means you can align views one by one (vertically/ horizontally). RelativeLayout means based on relation of views from its parents and other views. ConstraintLayout is similar to a RelativeLayout in that it uses relations to position and size widgets, but has additional flexibility and is easier to use in the Layout Editor. WebView to … Read more

getHeight returns 0 for all Android UI objects

It’s 0 because in both onCreate and onStart, the view hasn’t actually been drawn yet. You can get around this by listening for when the view is actually drawn: final TextView tv = (TextView)findViewById(R.id.venueLabel); final ViewTreeObserver observer= tv.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { tv.getHeight() observer.removeGlobalOnLayoutListener(this); } }); The call to remove the … Read more