Android : Draw Circle With Text Inside

Try this <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” > <RelativeLayout android:layout_width=”wrap_content” android:layout_height=”wrap_content” > <TextView android:id=”@+id/num_txt” android:layout_width=”100dp” android:layout_height=”100dp” android:layout_marginTop=”0dp” android:background=”@drawable/bg_red” android:gravity=”center” android:text=”My name is NON” android:textColor=”#FFFFFF” android:textSize=”10dp” /> </RelativeLayout> </RelativeLayout> Save in drawable bg_red.xml <?xml version=”1.0″ encoding=”utf-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”oval”> <corners android:radius=”10dip”/> <stroke android:color=”#FF0000″ android:width=”5dip”/> <solid android:color=”#FF0000″/> </shape> Edited Code <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” … Read more

How to add rectangles on top of existing rectangle in canvas

Try this: public class RectangleTextView extends View { private final Paint mBlackPaint = new Paint(); private final Paint mRedPaint = new Paint(); private final TextPaint mTextPaint; public RectangleTextView(Context context, AttributeSet attrs) { super(context, attrs); int valueInDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()); int valueInSp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics()); mRedPaint.setColor(Color.parseColor(“#CC3333”)); mBlackPaint.setAntiAlias(false); mBlackPaint.setColor(Color.BLACK); mBlackPaint.setStrokeWidth(valueInDp); mBlackPaint.setStyle(Paint.Style.STROKE); mTextPaint = … Read more

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

How to vary between child and parent view group touch events

The onTouchEvents() for nested view groups can be managed by the boolean onInterceptTouchEvent. The default value for the OnInterceptTouchEvent is false. The parent’s onTouchEvent is received before the child’s. If the OnInterceptTouchEvent returns false, it sends the motion event down the chain to the child’s OnTouchEvent handler. If it returns true the parent’s will handle … Read more

setVisibility(GONE) view becomes invisible but still occupies space

This is an Android bug in my opinion, we just fix this issue doing this: <FrameLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <LinearLayout android:id=”@+id/layout_to_hide” android:layout_width=”match_parent” android:layout_height=”wrap_content”> //Put here your views </LinearLayout> </FrameLayout> Just hide LinearLayout with id LAYOUT_TO_HIDE with Visible.GONE and then root FrameLayout will collapse its height giving you a “hidden” with non-blank-space header.