Tag: android-layout

Android how to add swipe Gesture on LinearLayout without onDown true

I’m working on Gesture activity in android I used class to detect the swipe action is public class ActivitySwipeDetector implements View.OnTouchListener { static final String logTag = “ActivitySwipeDetector”; private Activity activity; static final int MIN_DISTANCE = 100; private float downX, downY, upX, upY; public ActivitySwipeDetector(Activity activity){ this.activity = activity; } public void onRightToLeftSwipe(){ Log.i(logTag, “RightToLeftSwipe!”); […]

Removing padding from toggle button in Android

I am creating a simple toggle button in android and setting background as a drawable. <ToggleButton android:layout_width=”wrap_content” android:drawablePadding=”0dp” android:layout_height=”wrap_content” android:text=”” android:textSize=”12sp” android:padding=”0dp” android:id=”@+id/tag_text” android:background=”@drawable/toggle_selector”/> toggle_selector.xml looks like this: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:drawable=”@drawable/toggle_button_off” android:state_checked=”false”/> <item android:drawable=”@drawable/toggle_button_on” android:state_checked=”true”/> </selector> toggle_button_off and toggle_button_on have simple shape drawable with some color. And this is how I […]

Extending FrameLayout, child views won't show anymore

This is my code with FrameLayout: <FrameLayout android:layout_width=”fill_parent” android:layout_height=”wrap_content”> <ImageView android:id=”@+id/frameView” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:src=”@drawable/image1″ /> </FrameLayout> The ImageView show well. Now I have a custom layout extends from FrameLayout, e.g. MyFrameLayout. In MyFrameLayout, I want the height of the layout is always half of the width, so my code is: public class MyFrameLayout extends FrameLayout […]

alert dialog inside asynctask in android

I need to show the Alertdialog inside Asynctaskin android , but it won`t show in throws exception. 05-13 14:59:35.522: WARN/System.err(1179): java.lang.RuntimeException: Can’t create handler inside thread that has not called Looper.prepare() Thanks.

want to make some views invisible during runtime in android application

this is my main .xml file : <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:padding=”5dip” > <TextView android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:textColor=”@color/mbackground1″ android:gravity=”center_horizontal” android:text=”@string/decode_label” android:padding=”5dip” /> <TextView android:id=”@+id/mytext” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:gravity=”center_horizontal” android:background=”@color/mbackground2″ android:textColor=”@color/mytextcolor” android:padding=”5dip” /> <TextView android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”@string/continue_label” android:gravity=”center_horizontal” android:textColor=”@color/mytextcolor” android:padding=”5dip” /> <Button android:id=”@+id/webbutton” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”@string/web_button” android:textColor=”@color/mytextcolor” /> <TextView android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”@string/continue_label1″ android:gravity=”center_horizontal” android:textColor=”@color/mytextcolor” […]

how to avoid onCreateView() when swiping in tabs

I have an application with an activity and 3 swipable tabs(fragments). I have some heavily created UI elements inside tabs which take some time to be created and it’s ok for the first run, but the views are recreated every time I swipe them. When I select a tab, the other tab calls onStop() and […]

Activity with a transparent background

I’m creating a reusable Loading screen to use between Activities, on the LoadingActivity I added a semi transparent background resource, but I’m unable to see the old Activity. public class LoadingActivity extends Activity { public static int REQUEST_LOADING_SCREEN = 40; @Override protected void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); FrameLayout mainLayout = new FrameLayout(this); mainLayout.setBackgroundResource(R.drawable.background_translucent); LinearLayout layout […]

Is there any way to make table columns equal to a fraction of the total width?

So far in my learning I have only come across spreading column sizes equally, giving one/two a higher priority to take as much space as they need, or setting the size of a column manually. I was wondering if there was anyway of setting a column size in Android to be a fraction of the […]

Why does the LinearLayout attribute “layout_weight” seem to do the opposite of what I think it should do?

I’m following this tutorial to learn about linear layouts. Here’s the main layout file: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> <LinearLayout android:orientation=”horizontal” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:layout_weight=”1″> <TextView android:text=”red” android:gravity=”center_horizontal” android:background=”#aa0000″ android:layout_width=”wrap_content” android:layout_height=”fill_parent” android:layout_weight=”1″/> <TextView android:text=”green” android:gravity=”center_horizontal” android:background=”#00aa00″ android:layout_width=”wrap_content” android:layout_height=”fill_parent” android:layout_weight=”1″/> <TextView android:text=”blue” android:gravity=”center_horizontal” android:background=”#0000aa” android:layout_width=”wrap_content” android:layout_height=”fill_parent” android:layout_weight=”1″/> <TextView android:text=”yellow” android:gravity=”center_horizontal” android:background=”#aaaa00″ android:layout_width=”wrap_content” android:layout_height=”fill_parent” android:layout_weight=”1″/> […]

Displaying UI widgets in Cardview in android L

I am trying to create an application in cardview, the cardview contains two textviews which needs to be placed next to each other, but the textviews are getting overlapped. Is there any mechanism to place elements like its done in RelativeLayout(layout_below or layout_toRightOf) for Cardviews. I am able to do this by adding shadows to […]

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