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

Get Fragment dynamically attached to ?

Let me wrap it up by a full answer 🙂 In this case, the dynamically added Fragment uses the ID of the container View (ViewGroup). ref: http://developer.android.com/guide/components/fragments.html#Adding Note: Each fragment requires a unique identifier that the system can use to restore the fragment if the activity is restarted (and which you can use to capture … Read more

Scale background image to wrap content of layout

I had the same problem (I think), and the only solution I could find was this: <RelativeLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” > <View android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@drawable/some_image” android:layout_alignTop=”@+id/actual_content” android:layout_alignBottom=”@id/actual_content” android:layout_alignLeft=”@id/actual_content” android:layout_alignRight=”@id/actual_content” /> <LinearLayout android:id=”@id/actual_content” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_alignParentTop=”true” > <!– more stuff … –> </LinearLayout> </RelativeLayout>

Android: when / why should I use FrameLayout instead of Fragment?

The detail container is a FrameLayout because the Fragment that is displayed will be replaced using FragmentTransaction‘s replace() method. The first argument to replace() is the ID of container whose Fragments will be replaced. If the FrameLayout in this example were replaced with a Fragment, then both the WorkStationListFragment and whatever detail Fragment is currently … Read more

Android Fragment does not respect match_parent as height

I had the same problem and think it happens when you inflate the layout in the Fragment’s onCreateView with null, like you did here: mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null); Instead you have to do this: mRootView = (ViewGroup) inflater.inflate(R.layout.list_content,container, false); Where container is the Viewgroup. At least, that solved the problem for me.

FrameLayout vs RelativeLayout for overlays

A common rule of thumb when choosing layouts is to select the combination that results in the smallest number of nested layout views. Specific to your question, RelativeLayout is larger and more capable than the much simpler FrameLayout. So for simple layouts, the latter is probably more efficient. But if using RelativeLayout and it’s added … 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