Tag: layout

Building/using runtime generated layout XML in Android

I am currently working on a project which requires me to use an XML document to render a form on an Android device. The form must be fetched and displayed at run-time. I am wondering if there is a way to tag the form XML, transform it using XSLT into an Android layout XML, and […]

Fit a ImageView (and its src) to the layout width and make its height proportional

Can you help me to configure my layout? I don’t achieve what I’m looking for: I’ve put the imageview background to red for explain what I want: The image’s width is smaller than the layout width. I’d like the image grow proportionally keeping its aspect ratio until reach the aspect at the first image (I […]

Android get layout height and width in a fragment

I am working on a fragment and I want to get the dimension of a layout contained in the xml fragment layout. When I try the code RelativeLayout myLayout = view.findViewById(R.id.myLayout); myLayout.getHeight(); it returns 0. I need these dimensions to put inside myLayout other objects. I try to use: myLayout.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener(){ @Override public void […]

android: layout_marginBottom doesn't seem to work properly in 2.2 (Froyo)

I have this ImageView block inside a Relative layout: <ImageView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentBottom=”true” android:layout_marginBottom=”50dip” android:layout_marginLeft=”81dip” android:src=”@drawable/swipehelp” /> This draws the image right where it would be expected in both normal and high density resolution screens on Android 1.6 however on 2.2 it seems to ignore the layout_marginBottom and always draw the image aligned all the […]

Android LinearLayout Selector background color

Hi I’m trying to make my linear layout work like button. I mean I’m trying to change its background color when the state is changed. I used selector to solve it, but it didn’t work. I looked for solutions and all they say was add clickable attribute. I’ve already done that. My LinearLayout contains two […]

Android Problems Converting ViewGroup with Children into Bitmap

I’m successfully converting a ViewGroup (RelativeLayout) into Bitmap using a Canvas. However, when the draw happens I only see the ViewGroup with its background drawable and not its children (two TextViews) who should be laid out within the RelativeLayout using rules like FILL_PARENT. The RelativeLayout is created using the following static function: public static RelativeLayout […]

Android MenuItem Custom Layout

I have a PopupMenu that appears when I click on an action button in a actionbar. I would like the MenuItem, in my PopupMenu, with a custom layout like this: layout/menu_item_layout.xml <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/menuItemLayout” android:orientation=”horizontal” > <ImageView android:id=”@+id/imageViewMenuItem” android:layout_width=”20dip” android:layout_height=”20dip” android:src=”@drawable/abc_list_focused_holo” /> <TextView android:id=”@+id/textViewMenuItem” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”TextViewMenuItem” /> </LinearLayout> This is the xml […]

RelativeLayout's layout_above gives “No resource found” error

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” > <ListView android:layout_above=”@id/btn_4″ <– this line error: No resource found android:layout_width=”match_parent” android:layout_height=”200dp” /> <Button android:id=”@+id/btn_4″ <– I declare the id here android:layout_alignParentBottom=”true” android:layout_height=”wrap_content” android:layout_width=”match_parent” /> </RelativeLayout> Any suggestions?

Not enough space to show ad (AdMob)

I am trying to show AdMob ads in my activity, but it is always giving error that “not enough space to show ad”. My XML file is: <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:ads=”http://schemas.android.com/apk/lib/com.google.ads” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” 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=”.MainActivity” > <com.google.ads.AdView android:id=”@+id/adMobadView” android:layout_width=”fill_parent” android:layout_height=”fill_parent” ads:adSize=”BANNER” ads:adUnitId=”@string/admobid” android:layout_alignParentBottom=”true” android:gravity=”bottom|center_horizontal” ads:loadAdOnCreate=”true” /> </RelativeLayout> My Java file: AdView ad=(AdView)findViewById(R.id.adMobadView); […]

Stackoverflow: Caused by nested views?

I’m having a crash when refreshing a view inside a SlidingTray (custom SlidingDrawer coming from the top). I’m not sure what causing it.. but my first guess is that it’s due to the number of nested layouts… What is the maximum number of nested layouts? Is it device specific, how can I be sure if […]

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