DoubleTap gesture on a Image View - android

I am a beginner in Android and trying to make a simple tic-tac-toe game . At any time in the game , When a user double tap on a ImageView , I want the images to change (i.e) X will change to O and O will change to X . How do i implement that ?
Here is my code
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.view.GestureDetectorCompat;
public class MainActivity extends AppCompatActivity implements OnGestureListener ,GestureDetector.OnDoubleTapListener {
private GestureDetectorCompat gestureDetector;
int activePlayer =0; // if its 0 -> Cross , if its 1 -> circle
boolean gameActive = true;
int[] gameState ={2,2,2,2,2,2,2,2,2};
int[][] winningPosition = {{0,1,2},{3,4,5},{6,7,8},{0,4,8},{2,4,6},{0,3,6},{1,4,7},{2,5,8}};
ImageView counter;
public void dropIn (View view) {
counter = (ImageView) view;
System.out.println(counter.getTag().toString());
int tapCounter = Integer.parseInt(counter.getTag().toString());
if (gameState[tapCounter] == 2 && gameActive) {
gameState[tapCounter] = activePlayer;
counter.setTranslationY(-1000f);
if (activePlayer == 0) {
counter.setImageResource(R.drawable.o);
activePlayer = 1;
} else {
counter.setImageResource(R.drawable.a);
activePlayer = 0;
}
counter.animate().translationYBy(1000f).setDuration(600);
for(int[] winningPositions : winningPosition)
{
if(gameState[winningPositions[0]] == gameState[winningPositions[1]] && gameState[winningPositions[1]] == gameState[winningPositions[2]]
&& gameState[winningPositions[1]] != 2)
{
String winner = "Player 1";
gameActive = false;
if(gameState[winningPositions[0]] == 1)
{
winner = "Player 2";
}
TextView winnerMessage = (TextView) findViewById(R.id.winnerMessage);
winnerMessage.setText(winner + " has won !");
RelativeLayout hiddenLayout = (RelativeLayout)findViewById(R.id.playAgainLayout);
hiddenLayout.setVisibility(View.VISIBLE);}
else
{
boolean gameOver = true;
for(int counterState : gameState)
{
if(counterState == 2)
gameOver = false;
}
if(gameOver)
{
TextView winnerMessage = (TextView) findViewById(R.id.winnerMessage);
winnerMessage.setText("Its a draw");
RelativeLayout hiddenLayout = (RelativeLayout)findViewById(R.id.playAgainLayout);
hiddenLayout.setVisibility(View.VISIBLE);
}
}
}
}
}
#Override
public boolean onDoubleTap(MotionEvent e) {
if(gameState[0] ==0 || gameState[1] ==0 || gameState[2] ==0)
{
for (int i = 0;i<9;i++)
{
if(gameState[i] == 0)
{
counter.setImageResource(0);
counter.setImageResource(R.drawable.a);
gameState[i]=1;
}
else {
counter.setImageResource(R.drawable.a);
gameState[i]=0;
}
}
}
return true;
}
#Override
public boolean onDoubleTapEvent(MotionEvent e) {
Toast.makeText(getApplicationContext(),"Double Tap Event",Toast.LENGTH_LONG).show();
return true;
}
#Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return false;
}
public void exit()
{
Intent intent = new Intent(this, IntroActivity.class);
startActivity(intent);
}
public void playAgain(View view)
{
RelativeLayout hiddenLayout = (RelativeLayout)findViewById(R.id.playAgainLayout);
hiddenLayout.setVisibility(View.INVISIBLE);
activePlayer =0;
gameActive=true;
for(int i=0;i<gameState.length;i++)
{
gameState[i]=2;
}
GridLayout tableGrid = (GridLayout) findViewById(R.id.tableBorder);
for(int i=0;i<tableGrid.getChildCount();i++)
{
((ImageView) tableGrid.getChildAt(i)).setImageResource(0);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.gestureDetector = new GestureDetectorCompat(this,this);
gestureDetector.setOnDoubleTapListener(this);
}
#Override
public boolean onDown(MotionEvent e) {
return false;
}
#Override
public void onShowPress(MotionEvent e) {
}
#Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
#Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
#Override
public void onLongPress(MotionEvent e) {
}
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
#Override
public boolean onTouchEvent(MotionEvent event) {
this.gestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
}
And my XML Code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="com.adarshjayakumar.mygame.MainActivity"
android:background="#f2eddc">
<GridLayout
android:layout_width="302dp"
android:layout_height="302dp"
android:columnCount="3"
android:rowCount="3"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_centerInParent="true"
android:layout_alignParentRight="false"
android:background="#drawable/able"
android:id="#+id/tableBorder">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView"
android:layout_row="0"
android:layout_column="0"
android:tag="0"
android:onClick="dropIn"
/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView1"
android:layout_row="0"
android:layout_column="1"
android:tag="1"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView2"
android:layout_row="0"
android:layout_column="2"
android:tag="2"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView3"
android:layout_row="1"
android:layout_column="0"
android:tag="3"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView4"
android:layout_row="1"
android:layout_column="1"
android:tag="4"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView5"
android:layout_row="1"
android:layout_column="2"
android:tag="5"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView6"
android:layout_row="2"
android:layout_column="0"
android:tag="6"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView7"
android:layout_row="2"
android:layout_column="1"
android:tag="7"
android:onClick="dropIn" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView8"
android:layout_row="2"
android:layout_column="2"
android:tag="8"
android:onClick="dropIn" />
</GridLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_alignParentBottom="false"
android:layout_centerVertical="true"
android:background="#f96262"
android:id="#+id/playAgainLayout"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Game Over"
android:id="#+id/textView"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play Again"
android:id="#+id/button"
android:layout_marginTop="60dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_below="#+id/textView"
android:layout_alignParentStart="true"
android:layout_marginStart="48dp"
android:onClick="playAgain" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:id="#+id/button2"
android:layout_alignTop="#+id/button"
android:layout_toEndOf="#+id/textView"
android:onClick="exit" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play 1 has won"
android:id="#+id/winnerMessage"
android:layout_above="#+id/button2"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:textSize="18dp" />
</RelativeLayout>
</RelativeLayout>

It's always good to read up on the original Google documents when u first start. http://developer.android.com/reference/android/support/v4/view/GestureDetectorCompat.html gesture detector lets u detect double click.

Related

How to use swipe up/down approach in android layout?

I am using Two Relative layouts.one relative layout consists of edit boxes and spinner (Lime color layout).The other relative Layout consists of only web view. I wish to use swipe up/down approach to relative layout(Lime color). If the user swipe up the lime colored layout.other layout will be display in full screen. I don't know how to achieve. I need any reference or article to complete.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#C6FF00">
<LinearLayout
android:id="#+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:background="#defec8">
<EditText
android:id="#+id/fromDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="From Date" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#+id/linear"
android:layout_toRightOf="#+id/linear"
android:background="#defec8"
android:orientation="horizontal">
<EditText
android:id="#+id/todate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="To Date" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#+id/linear1"
android:layout_toRightOf="#+id/linear1"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/timespinner"
android:layout_width="80dp"
android:layout_height="42dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="40dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/linear4"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/nametype"
android:layout_width="80dp"
android:layout_height="40dp">
</Spinner>
</LinearLayout>
<LinearLayout
android:id="#+id/linear3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linear4"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#id/linear5"
android:layout_toRightOf="#id/linear5"
android:background="#defec8"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<Spinner
android:id="#+id/digitspinner"
android:layout_width="80dp"
android:layout_height="40dp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/linearweb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/rL"
android:layout_marginBottom="10dp">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</LinearLayout>
</RelativeLayout>
This works perfectly for me
My custom Gesture Detector Class. Copy and paste in appropriate package.
package com.cse.stackoverflow.gesture;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
public abstract class CustomGestureDetector extends android.view.GestureDetector.SimpleOnGestureListener {
private static final String TAG = CustomGestureDetector.class.getSimpleName();
private View view;
private boolean selectionStart;
public CustomGestureDetector(View view) {
this.view = view;
}
//FOR GESTURE
#Override
public boolean onFling(MotionEvent motionEventOne, MotionEvent motionEventTwo, float velocityX, float velocityY) {
if (motionEventOne == null || motionEventTwo == null) {
return false;
} else if (motionEventOne.getPointerCount() > 1 || motionEventTwo.getPointerCount() > 1) {
return false;
} else {
if (isSelectionStart()) {
Log.d(TAG, "ME 1 : X - " + motionEventOne.getX());
Log.d(TAG, "ME 1 : Y - " + motionEventOne.getY());
Log.d(TAG, "ME 2 : X - " + motionEventTwo.getX());
Log.d(TAG, "ME 2 : Y - " + motionEventTwo.getY());
Log.d(TAG, "Velocity Of X - " + velocityX);
Log.d(TAG, "Velocity Of Y - " + velocityY);
} else {
try {
///////////////////////////////////////////////////////////////////////////////
Log.d(TAG, "ME 1 : X - " + motionEventOne.getX());
Log.d(TAG, "ME 1 : Y - " + motionEventOne.getY());
Log.d(TAG, "ME 2 : X - " + motionEventTwo.getX());
Log.d(TAG, "ME 2 : Y - " + motionEventTwo.getY());
Log.d(TAG, "Velocity Of X - " + velocityX);
Log.d(TAG, "Velocity Of Y - " + velocityY);
float mRightToLeftCover = motionEventOne.getX() - motionEventTwo.getX();
float mTopToBottomCover = motionEventTwo.getY() - motionEventOne.getY();
float mVelocityX = velocityX;
float mVelocityY = velocityY;
Log.i(TAG, "mRightToLeftCover : " + mRightToLeftCover);
Log.i(TAG, "mTopToBottomCover : " + mTopToBottomCover);
Log.i(TAG, "mVelocityX : " + mVelocityX);
Log.i(TAG, "mVelocityY : " + mVelocityY);
if (mRightToLeftCover >= 0) {
if (mTopToBottomCover >= 0) {
if (mTopToBottomCover < 100) {
if (mRightToLeftCover > 100) {
Log.d(TAG, "1. R =>> L");
onRightToLeftSwap();
}
} else {
if (mRightToLeftCover < 100) {
Log.d(TAG, "9. T ==>> B");
onTopToBottomSwap();
} else {
Log.d(TAG, "2. T ==>> B, R =>> L");
}
}
} else {
if (mTopToBottomCover > -100) {
if (mRightToLeftCover > 100) {
Log.d(TAG, "3. R =>> L");
onRightToLeftSwap();
}
} else {
if (mRightToLeftCover < 100) {
Log.d(TAG, "10. B ==>> T");
onBottomToTopSwap();
} else {
Log.d(TAG, "4. B ==>> T, R =>> L");
}
}
}
} else if (mRightToLeftCover < 0) {
if (mTopToBottomCover >= 0) {
if (mTopToBottomCover < 100) {
if (mRightToLeftCover > -100) {
Log.d(TAG, "5. L =>> R");
onLeftToRightSwap();
}
} else {
if (mRightToLeftCover > -100) {
Log.d(TAG, "11. T ==>> B");
onTopToBottomSwap();
} else {
Log.d(TAG, "6. T ==>> B, L =>> R");
}
}
} else {
if (mTopToBottomCover > -100) {
if (mRightToLeftCover < -100) {
Log.d(TAG, "7. L =>> R");
onLeftToRightSwap();
}
} else {
if (mRightToLeftCover < -100) {
Log.d(TAG, "12. B ==>> T");
onBottomToTopSwap();
} else {
Log.d(TAG, "8. B ==>> T, L =>> R");
}
}
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
//////////////////////////////////////////////////////////////////////////////
return false;
}
}
//EXPERIMENTAL PURPOSE
public abstract void onLeftToRightSwap();
public abstract void onRightToLeftSwap();
public abstract void onTopToBottomSwap();
public abstract void onBottomToTopSwap();
public abstract void onLeftToRightTopToBottomDiagonalSwap();
public abstract void onLeftToRightBottomToTopDiagonalSwap();
public abstract void onRightToLeftTopToBottomDiagonalSwap();
public abstract void onRightToLeftBottomToTopDiagonalSwap();
//SINGLE AND DOUBLE TABS
#Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Log.d(TAG, "On Single Tap");
Log.d(TAG, "Selection Start : " + selectionStart);
Log.d(TAG, "ME 1 : X - " + e.getX());
Log.d(TAG, "ME 1 : Y - " + e.getY());
onSingleTap();
return super.onSingleTapConfirmed(e);
}
#Override
public boolean onDoubleTap(MotionEvent e) {
Log.d(TAG, "On Double Tap");
onDoubleTap();
return super.onDoubleTap(e);
}
public abstract void onSingleTap();
public abstract void onDoubleTap();
public boolean isSelectionStart() {
return selectionStart;
}
public void setSelectionStart(boolean selectionStart) {
this.selectionStart = selectionStart;
}
#Override
public void onLongPress(MotionEvent e) {
onLongPressPerformed(e);
super.onLongPress(e);
}
public abstract void onLongPressPerformed(MotionEvent e);
}
activity_main.xml just small modification i.e. I set id "webView" to your webView. (Copy and paste this xml code into your xml file).
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="#+id/rL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#C6FF00">
<LinearLayout
android:id="#+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:background="#defec8">
<EditText
android:id="#+id/fromDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="From Date" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#+id/linear"
android:layout_toRightOf="#+id/linear"
android:background="#defec8"
android:orientation="horizontal">
<EditText
android:id="#+id/todate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="To Date" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#+id/linear1"
android:layout_toRightOf="#+id/linear1"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/timespinner"
android:layout_width="80dp"
android:layout_height="42dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="40dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/linear4"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/nametype"
android:layout_width="80dp"
android:layout_height="40dp">
</Spinner>
</LinearLayout>
<LinearLayout
android:id="#+id/linear3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linear4"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#id/linear5"
android:layout_toRightOf="#id/linear5"
android:background="#defec8"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<Spinner
android:id="#+id/digitspinner"
android:layout_width="80dp"
android:layout_height="40dp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/linearweb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/rL"
android:layout_alignParentBottom="true">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</LinearLayout>
</RelativeLayout>
MainActivity code (Copy and paste all methods and call initialiseView() method in onCreate())
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialiseView();
}
RelativeLayout upperLayout;
LinearLayout lowerLayout;
WebView mWebView;
private void initialiseView() {
upperLayout = (RelativeLayout) findViewById(R.id.rL);
lowerLayout = (LinearLayout) findViewById(R.id.linearweb);
mWebView = (WebView) findViewById(R.id.webView);
CustomGestureDetector mCustomGestureDetectorForUpperLayout = new CustomGestureDetector(upperLayout) {
#Override
public void onLeftToRightSwap() {
}
#Override
public void onRightToLeftSwap() {
}
#Override
public void onTopToBottomSwap() {
//Toast.makeText(MainActivity.this, "onTopToBottomSwap", Toast.LENGTH_SHORT).show();
showUpperLayout();
}
#Override
public void onBottomToTopSwap() {
//Toast.makeText(MainActivity.this, "onBottomToTopSwap", Toast.LENGTH_SHORT).show();
hideUpperLayout();
}
#Override
public void onLeftToRightTopToBottomDiagonalSwap() {
}
#Override
public void onLeftToRightBottomToTopDiagonalSwap() {
}
#Override
public void onRightToLeftTopToBottomDiagonalSwap() {
}
#Override
public void onRightToLeftBottomToTopDiagonalSwap() {
}
#Override
public void onSingleTap() {
}
#Override
public void onDoubleTap() {
}
#Override
public void onLongPressPerformed(MotionEvent e) {
}
};
final GestureDetector mGestureDetectorUpperLayout = new GestureDetector(this, mCustomGestureDetectorForUpperLayout);
CustomGestureDetector mCustomGestureDetectorForLowerLayout = new CustomGestureDetector(lowerLayout) {
#Override
public void onLeftToRightSwap() {
}
#Override
public void onRightToLeftSwap() {
}
#Override
public void onTopToBottomSwap() {
showUpperLayout();
}
#Override
public void onBottomToTopSwap() {
}
#Override
public void onLeftToRightTopToBottomDiagonalSwap() {
}
#Override
public void onLeftToRightBottomToTopDiagonalSwap() {
}
#Override
public void onRightToLeftTopToBottomDiagonalSwap() {
}
#Override
public void onRightToLeftBottomToTopDiagonalSwap() {
}
#Override
public void onSingleTap() {
}
#Override
public void onDoubleTap() {
}
#Override
public void onLongPressPerformed(MotionEvent e) {
}
};
final GestureDetector mGestureDetectorLowerLayout = new GestureDetector(this, mCustomGestureDetectorForLowerLayout);
upperLayout.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
mGestureDetectorUpperLayout.onTouchEvent(motionEvent);
return true;
}
});
lowerLayout.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
mGestureDetectorLowerLayout.onTouchEvent(motionEvent);
return true;
}
});
mWebView.loadUrl("https://www.google.co.in/");
CustomGestureDetector mCustomGestureDetectorForWebView = new CustomGestureDetector(mWebView) {
#Override
public void onLeftToRightSwap() {
}
#Override
public void onRightToLeftSwap() {
}
#Override
public void onTopToBottomSwap() {
showUpperLayout();
}
#Override
public void onBottomToTopSwap() {
hideUpperLayout();
}
#Override
public void onLeftToRightTopToBottomDiagonalSwap() {
}
#Override
public void onLeftToRightBottomToTopDiagonalSwap() {
}
#Override
public void onRightToLeftTopToBottomDiagonalSwap() {
}
#Override
public void onRightToLeftBottomToTopDiagonalSwap() {
}
#Override
public void onSingleTap() {
}
#Override
public void onDoubleTap() {
}
#Override
public void onLongPressPerformed(MotionEvent e) {
}
};
final GestureDetector mGestureDetectorForWebView = new GestureDetector(this, mCustomGestureDetectorForWebView);
mWebView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
mGestureDetectorForWebView.onTouchEvent(motionEvent);
return true;
}
});
}
public void hideUpperLayout() {
upperLayout.setVisibility(View.GONE);
}
public void showUpperLayout() {
upperLayout.setVisibility(View.VISIBLE);
}
public void toggleUpperLayout() {
if (upperLayout.getVisibility() == View.VISIBLE) {
hideUpperLayout();
} else {
showUpperLayout();
}
}
}
This is optional(to see google home page on your webview).
//Add internet permission in AndroidMenifest.xml
<uses-permission android:name="android.permission.INTERNET" />
Update As Per Comment For Smooth Scroll
To Achieve Smooth Scrolling you need need to use AppBarLayout inside parent layout(Parent layout may be anything for easy use Coordinator layout).
First in your style.xml create themes entry like below or just copy and paste it.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
For colours need to create colors.xml (If you created app its have default entries)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Now your activity_main.xml is like below.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.cse.scrolltoolbar.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:id="#+id/rL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#C6FF00"
android:paddingTop="100dp"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay">
<LinearLayout
android:id="#+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:background="#defec8">
<EditText
android:id="#+id/fromDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="From Date" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#+id/linear"
android:layout_toRightOf="#+id/linear"
android:background="#defec8"
android:orientation="horizontal">
<EditText
android:id="#+id/todate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="To Date" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#+id/linear1"
android:layout_toRightOf="#+id/linear1"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/timespinner"
android:layout_width="80dp"
android:layout_height="42dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="40dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/linear4"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/nametype"
android:layout_width="80dp"
android:layout_height="40dp">
</Spinner>
</LinearLayout>
<LinearLayout
android:id="#+id/linear3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linear4"
android:layout_marginBottom="10dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="#id/linear5"
android:layout_toRightOf="#id/linear5"
android:background="#defec8"
android:orientation="horizontal">
<Spinner
android:id="#+id/digitspinner"
android:layout_width="80dp"
android:layout_height="40dp" />
</LinearLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!--<include layout="#layout/content_scrolling" />-->
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</WebView>
</android.support.design.widget.CoordinatorLayout>
Add internet permission in Manifest file and add below method to load google home page to your web view and call this method from onCreate after setContentView.
private void initialiseView() {
WebView mWebView = (WebView) findViewById(R.id.webView);
mWebView.loadUrl("https://www.google.co.in/");
}

Android radiogroup with nested linearlayouts not deselecting radiobuttons [duplicate]

This question already has answers here:
How to group RadioButton from different LinearLayouts?
(21 answers)
Closed 5 years ago.
I have a group of radiobuttons in a radiogroup that refuses to behave the way I'd like. The radiobuttons need to be two lines of two, and one line of one, with the last button having an edittext instead of a label. The layout looks correct, but the radiobuttons allow more than one to be selected and won't deselect any.
Below is my XML:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rgDesignation">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/llVT1">
<RadioButton
android:text="#string/pressure_equipment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rbPE"
android:layout_weight="1" />
<RadioButton
android:text="#string/assemblies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rbAss"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/llVT2">
<RadioButton
android:text="#string/unheated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rbUnh"
android:layout_weight="1" />
<RadioButton
android:text="#string/heated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rbH"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/llVT3">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rbOwnSel"
android:layout_weight="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:id="#+id/etOwnChoice"
android:layout_weight="1"
android:textColor="#android:color/black"
android:background="#android:color/white"
android:elevation="5dp" />
</LinearLayout>
</RadioGroup>
Make custom RadioGroup class like this:
public class RadioGroup extends LinearLayout {
private int mCheckedId = -1;
private CompoundButton.OnCheckedChangeListener mChildOnCheckedChangeListener;
private boolean mProtectFromCheckedChange = false;
private OnCheckedChangeListener mOnCheckedChangeListener;
private PassThroughHierarchyChangeListener mPassThroughListener;
public RadioGroup(Context context) {
super(context);
setOrientation(VERTICAL);
init();
}
public RadioGroup(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
mChildOnCheckedChangeListener = new CheckedStateTracker();
mPassThroughListener = new PassThroughHierarchyChangeListener();
super.setOnHierarchyChangeListener(mPassThroughListener);
}
#Override
public void setOnHierarchyChangeListener(OnHierarchyChangeListener listener) {
mPassThroughListener.mOnHierarchyChangeListener = listener;
}
#Override
protected void onFinishInflate() {
super.onFinishInflate();
if (mCheckedId != -1) {
mProtectFromCheckedChange = true;
setCheckedStateForView(mCheckedId, true);
mProtectFromCheckedChange = false;
setCheckedId(mCheckedId);
}
}
#Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
if (child instanceof RadioButton) {
final RadioButton button = (RadioButton) child;
if (button.isChecked()) {
mProtectFromCheckedChange = true;
if (mCheckedId != -1) {
setCheckedStateForView(mCheckedId, false);
}
mProtectFromCheckedChange = false;
setCheckedId(button.getId());
}
}
super.addView(child, index, params);
}
public void check(#IdRes int id) {
// don't even bother
if (id != -1 && (id == mCheckedId)) {
return;
}
if (mCheckedId != -1) {
setCheckedStateForView(mCheckedId, false);
}
if (id != -1) {
setCheckedStateForView(id, true);
}
setCheckedId(id);
}
private void setCheckedId(#IdRes int id) {
mCheckedId = id;
if (mOnCheckedChangeListener != null) {
mOnCheckedChangeListener.onCheckedChanged(this, mCheckedId);
}
}
private void setCheckedStateForView(int viewId, boolean checked) {
View checkedView = findViewById(viewId);
if (checkedView != null && checkedView instanceof RadioButton) {
((RadioButton) checkedView).setChecked(checked);
}
}
#IdRes
public int getCheckedRadioButtonId() {
return mCheckedId;
}
public void clearCheck() {
check(-1);
}
public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
mOnCheckedChangeListener = listener;
}
#Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
}
#Override
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
return p instanceof RadioGroup.LayoutParams;
}
#Override
protected LinearLayout.LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
#Override
public CharSequence getAccessibilityClassName() {
return RadioGroup.class.getName();
}
public static class LayoutParams extends LinearLayout.LayoutParams {
public LayoutParams(Context c, AttributeSet attrs) {
super(c, attrs);
}
public LayoutParams(int w, int h) {
super(w, h);
}
public LayoutParams(int w, int h, float initWeight) {
super(w, h, initWeight);
}
public LayoutParams(ViewGroup.LayoutParams p) {
super(p);
}
public LayoutParams(MarginLayoutParams source) {
super(source);
}
#Override
protected void setBaseAttributes(TypedArray a,
int widthAttr, int heightAttr) {
if (a.hasValue(widthAttr)) {
width = a.getLayoutDimension(widthAttr, "layout_width");
} else {
width = WRAP_CONTENT;
}
if (a.hasValue(heightAttr)) {
height = a.getLayoutDimension(heightAttr, "layout_height");
} else {
height = WRAP_CONTENT;
}
}
}
public void onCheckedChanged(RadioGroup group, #IdRes int checkedId);
}
private class CheckedStateTracker implements CompoundButton.OnCheckedChangeListener {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// prevents from infinite recursion
if (mProtectFromCheckedChange) {
return;
}
mProtectFromCheckedChange = true;
if (mCheckedId != -1) {
setCheckedStateForView(mCheckedId, false);
}
mProtectFromCheckedChange = false;
int id = buttonView.getId();
setCheckedId(id);
}
}
private class PassThroughHierarchyChangeListener implements
ViewGroup.OnHierarchyChangeListener {
private ViewGroup.OnHierarchyChangeListener mOnHierarchyChangeListener;
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public void traverseTree(View view) {
if (view instanceof RadioButton) {
int id = view.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
id = View.generateViewId();
view.setId(id);
}
((RadioButton) view).setOnCheckedChangeListener(
mChildOnCheckedChangeListener);
}
if (!(view instanceof ViewGroup)) {
return;
}
ViewGroup viewGroup = (ViewGroup) view;
if (viewGroup.getChildCount() == 0) {
return;
}
for (int i = 0; i < viewGroup.getChildCount(); i++) {
traverseTree(viewGroup.getChildAt(i));
}
}
/**
* {#inheritDoc}
*/
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public void onChildViewAdded(View parent, View child) {
traverseTree(child);
if (parent == RadioGroup.this && child instanceof RadioButton) {
int id = child.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
id = View.generateViewId();
child.setId(id);
}
((RadioButton) child).setOnCheckedChangeListener(
mChildOnCheckedChangeListener);
}
if (mOnHierarchyChangeListener != null) {
mOnHierarchyChangeListener.onChildViewAdded(parent, child);
}
}
/**
* {#inheritDoc}
*/
public void onChildViewRemoved(View parent, View child) {
if (parent == RadioGroup.this && child instanceof RadioButton) {
((RadioButton) child).setOnCheckedChangeListener(null);
}
if (mOnHierarchyChangeListener != null) {
mOnHierarchyChangeListener.onChildViewRemoved(parent, child);
}
}
}
}
and add in your layout like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="#dimen/activity_vertical_margin"
>
<com.example.admin.myapplication.RadioGroup
android:id="#+id/radio_group_plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<RadioButton
android:id="#+id/rb_latte"
android:text="radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<RadioButton
android:text="radio2"
android:id="#+id/rb_latte1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#E0E0E0" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<ImageView
android:id="#+id/iv_mocha"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/iv_mocha"
android:paddingLeft="20dp"
android:text="Mocha" />
<RadioButton
android:id="#+id/rb_mocha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#E0E0E0" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<ImageView
android:id="#+id/iv_americano"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/iv_americano"
android:paddingLeft="20dp"
android:text="Americano" />
<RadioButton
android:id="#+id/rb_americano"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#E0E0E0" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<ImageView
android:id="#+id/iv_espresso"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/iv_espresso"
android:paddingLeft="20dp"
android:text="Espresso" />
<RadioButton
android:id="#+id/rb_espresso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#E0E0E0" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1">
<ImageView
android:id="#+id/iv_orange"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/iv_orange"
android:paddingLeft="20dp"
android:text="Orange" />
<RadioButton
android:id="#+id/rb_orange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<View
android:layout_width="2dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#E0E0E0" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:paddingLeft="10dp">
<ImageView
android:id="#+id/iv_butter"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/iv_butter"
android:paddingLeft="20dp"
android:text="Butter" />
<RadioButton
android:id="#+id/rb_butter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</LinearLayout>
</com.example.admin.myapplication.RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#138BE8"
android:gravity="center"
android:onClick="onOrderClicked"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Order Drink"
android:textColor="#android:color/white" />

Draw images on evey touch co-ordinats Of Imageview

I want to draw small circular images at every point where user touches existing Image-view in android.And want to handle the click of every small ploted image.Right now I am trying to draw circluar image on ImageView but its not working for me.
Here is my code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical"
android:weightSum="2" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:background="#EEEDEE"
android:gravity="center"
android:orientation="horizontal"
android:padding="20dp"
android:weightSum="4" >
<ImageView
android:id="#+id/img_overview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/img_specifications"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/img_features"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/img_resources"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#FFFFFF"
android:orientation="vertical"
android:padding="20dp" >
<Textview
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Siss "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#CE561B"
android:textStyle="bold|italic" />
<Textview
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="dummy long text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black_color" />
<FrameLayout
android:id="#+id/ll_img_bigview_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.example.htmlcheck.CustomImageView
android:id="#+id/img_big_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/sj"/>
</FrameLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
dimension of sj image is 900 X 600 pixels.
My CustomImageView Class :
package com.example.htmlcheck;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;
public class CustomImageView extends ImageView {
private ArrayList<Point> mTouches;
private Bitmap mMarker;
// Java constructor
public CustomImageView(Context context) {
super(context);
init();
}
// XML constructor
public CustomImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
mTouches = new ArrayList<Point>();
mMarker = BitmapFactory.decodeResource(this.getResources(),
R.drawable.cross_small);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
// Capture a reference to each touch for drawing
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mTouches.add(new Point((int) event.getX(), (int) event.getY()));
return true;
}
return super.onTouchEvent(event);
}
#Override
protected void onDraw(Canvas c) {
// Let the image be drawn first
super.onDraw(c);
// Draw your custom points here
Paint paint = new Paint();
for (Point p : mTouches) {
c.drawBitmap(mMarker, p.x, p.y, paint);
}
}
}
My activity :
public class MainActivity extends Activity implements OnClickListener {
private CustomImageView mImgBigImageview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImgBigImageview = (CustomImageView) findViewById(R.id.img_big_imageview);
mImgBigImageview.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.onTouchEvent(event)) {
}
return true;
}
});
}
Any Help will be appreciated.
Thanks.
Here you go :-
mImgBigImageview.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
CustomImageView mcustomImagview = (CustomImageView) v;
mcustomImagview.invalidate();
if (v.onTouchEvent(event)) {
// Do something with event.getX(), event.getY()
}
return true;
}
});

how to make Footer buttons appears while dragging screen down in android like in facebook app

I wanna make footer buttons in android one way is to simply make buttons and align them to bottom but I want the footer like in Facebook android app whenever we drag screen down three buttons appears for status , photo , checkin.
How to do this ??
To get a list like the following image, create a layout.xml as follows after the sample image
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" >
<RelativeLayout
android:id="#+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/header" >
<LinearLayout
android:id="#+id/BtnSlide"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:background="#drawable/button_bg_drawable" >
<ImageView
android:id="#+id/imageView0"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_vertical|left"
android:background="#drawable/button_bg_drawable"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:src="#drawable/back_btn_small" />
</LinearLayout>
<EditText
android:id="#+id/headerText"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toRightOf="#id/BtnSlide"
android:background="#android:drawable/editbox_background_normal"
android:editable="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="normal" />
<AutoCompleteTextView
android:id="#+id/filterNewProject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_toRightOf="#id/BtnSlide"
android:background="#drawable/bg_input_blue"
android:completionThreshold="1"
android:hint="Search for a locality, developer or project"
android:textColor="#color/black"
android:textSize="14sp"
android:visibility="gone" />
<Button
android:id="#+id/clearAutoCompleteList"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/custom_button_clear"
android:paddingLeft="20dp"
android:visibility="gone" />
<Button
android:id="#+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:background="#drawable/seaerch_glass" />
<View
android:id="#+id/sep_header"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_below="#id/tabBar"
android:background="#d5d5d5"
android:visibility="visible" />
</RelativeLayout>
<include
android:id="#+id/footerLayout"
layout="#layout/post_requirement_footer"
android:visibility="gone" />
<ListView
android:id="#+id/projectsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footerLayout"
android:layout_below="#id/headerLayout"
android:divider="#color/white"
android:dividerHeight="1.5dp" >
</ListView>
<RelativeLayout
android:id="#+id/zeroResultsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footerLayout"
android:layout_below="#id/headerLayout"
android:visibility="gone" >
<ImageView
android:id="#+id/emptyIllustration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/no_results_illustration" />
</RelativeLayout>
<com.housing.utils.QuickReturnRelativeLayoutFooter
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:background="#color/transparent" >
<RelativeLayout
android:id="#+id/bottomListViewContainer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#drawable/footer_bg" >
<ImageButton
android:id="#+id/filterButtonFooter"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/button_bg_drawable"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:src="#drawable/filter_icon" />
<ImageButton
android:id="#+id/subscribeButtonFooter"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/button_bg_drawable"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:src="#drawable/subscribe_iphone"
android:visibility="visible" />
<TextView
android:id="#+id/resultsText"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ellipsize="end"
android:paddingTop="10dp"
android:scrollHorizontally="false"
android:singleLine="false"
android:text=""
android:textColor="#color/black"
android:textSize="15dp"
android:visibility="visible" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/resultsText"
android:paddingRight="5dp"
android:paddingTop="15dp"
android:src="#drawable/filter_normal"
android:visibility="gone" />
</RelativeLayout>
</com.housing.utils.QuickReturnRelativeLayoutFooter>
</RelativeLayout>
Here is the Class com.housing.utils.QuickReturnRelativeLayoutFooter
PS : Replace com.housing.utils with your package name
package com.housing.utils;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.RelativeLayout;
public class QuickReturnRelativeLayoutFooter extends RelativeLayout implements
OnScrollListener {
private class ChildDescriptor {
public int index;
public int total;
public int drawable;
public ChildDescriptor(int index) {
this.index = index;
}
public int getApproximateScrollPosition() {
return index * total + (total - drawable);
}
}
public int MAX_HEIGHT_DP =60;
public int MIN_HEIGHT_DP = 0;
public static final int SCROLL_DIRECTION_INVALID = 0;
public static final int SCROLL_DIRECTION_UP = 1;
public static final int SCROLL_DIRECTION_DOWN = 2;
private int direction = SCROLL_DIRECTION_INVALID;
private ChildDescriptor lastchild;
private OnScrollListener onscrolllistener;
private int maxheight;
private int minheight;
public QuickReturnRelativeLayoutFooter(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
calculateMinMax();
}
public QuickReturnRelativeLayoutFooter(Context context, AttributeSet attrs) {
super(context, attrs);
calculateMinMax();
}
public QuickReturnRelativeLayoutFooter(Context context) {
super(context);
calculateMinMax();
}
private void calculateMinMax() {
DisplayMetrics metrics = getResources().getDisplayMetrics();
maxheight = (int) (metrics.density * (float) MAX_HEIGHT_DP);
minheight = (int) (metrics.density * (float) MIN_HEIGHT_DP);
}
private void adjustHeight(int howmuch, int max, int min) {
if ((howmuch < 0) && (direction != SCROLL_DIRECTION_UP)) {
direction = SCROLL_DIRECTION_UP;
return;
} else if ((howmuch > 20) && (direction != SCROLL_DIRECTION_DOWN)) {
direction = SCROLL_DIRECTION_DOWN;
return;
}
int current = getHeight();
current += howmuch;
if (current < min) {
current = min;
} else if (current > max) {
current = max;
}
RelativeLayout.LayoutParams f = (RelativeLayout.LayoutParams) getLayoutParams();
if (f.height != current) {
f.height = current;
setLayoutParams(f);
}
if (direction == SCROLL_DIRECTION_UP
&& Math.abs(f.topMargin) <= current) {
// if (f.topMargin != howmuch) {
//
// f.topMargin = howmuch + f.topMargin;
//
// if (f.topMargin > 0) {
// f.topMargin = -f.topMargin - 10;
// }
//
// }
// mBottomListViewContainer.setVisibility(View.GONE);
f.bottomMargin = -100;
setLayoutParams(f);
} else if (direction == SCROLL_DIRECTION_DOWN) {
if (f.bottomMargin != 0) {
f.bottomMargin = 0;
setLayoutParams(f);
}
}
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
ChildDescriptor currentchild = getFirstChildItemDescriptor(view,
firstVisibleItem);
try {
adjustHeight(lastchild.getApproximateScrollPosition()
- currentchild.getApproximateScrollPosition(), maxheight,
minheight);
lastchild = currentchild;
} catch (NullPointerException e) {
lastchild = currentchild;
} catch (Exception e) {
}
if (onscrolllistener != null) {
onscrolllistener.onScroll(view, firstVisibleItem, visibleItemCount,
totalItemCount);
}
}
private ChildDescriptor getFirstChildItemDescriptor(AbsListView view,
int index) {
ChildDescriptor h = new ChildDescriptor(index);
try {
Rect r = new Rect();
View child = view.getChildAt(0);
child.getDrawingRect(r);
h.total = r.height();
view.getChildVisibleRect(child, r, null);
h.drawable = r.height();
return h;
} catch (Exception e) {
}
return null;
}
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (onscrolllistener != null) {
onscrolllistener.onScrollStateChanged(view, scrollState);
}
}
public void attach(AbsListView view) {
view.setOnScrollListener(this);
}
public void setOnScrollListener(OnScrollListener l) {
onscrolllistener = l;
}
}
I Have made it as a widget and Now finally to add this to your List View use
frame = (QuickReturnRelativeLayoutFooter) newProjectsView
.findViewById(R.id.frame);
frame.attach(projectsList);
where projectList is your List View
example
ListView projectList =(ListView)findViewById(R.id.projectList);
and Voila Cheers Completed Smooth as Heaven .......

Pass screen coordinates from button to parent

I am making a piano app for android. As a sample(test), I have 4 buttons in my activity. The parent is a Relative Layout and I also have a few textviews that tell the screen coordinates of the finger touch. There is one more textView("Entered Button") that detects if your finger is over a button or notThis is what it looks like:
I achieved this using the code given below.
Java
public class MainActivity extends Activity {
Button b1, b2, b3, b4;
int b1x1, b1x2, b1y1, b1y2;
private TextView xcordview;
private TextView ycordview;
private TextView buttonIndicator;
private RelativeLayout touchview;
private static int defaultStates[];
private Button mLastButton;
private final static int[] STATE_PRESSED = {
android.R.attr.state_pressed,
android.R.attr.state_focused
| android.R.attr.state_enabled };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xcordview = (TextView) findViewById(R.id.textView4);
ycordview = (TextView) findViewById(R.id.textView3);
buttonIndicator = (TextView) findViewById(R.id.button_indicator);
touchview = (RelativeLayout) findViewById(R.id.relativelayout);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button) findViewById(R.id.button3);
b4 = (Button) findViewById(R.id.button4);
defaultStates = b1.getBackground().getState();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
touchview.setOnTouchListener(new View.OnTouchListener() {
private boolean isInside = false;
#Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
xcordview.setText(String.valueOf(x));
ycordview.setText(String.valueOf(y));
for (int i = 0; i < touchview.getChildCount(); i++) {
View current = touchview.getChildAt(i);
if (current instanceof Button) {
Button b = (Button) current;
if (!isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
b.getBottom())) {
b.getBackground().setState(defaultStates);
}
if (isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
b.getBottom())) {
b.getBackground().setState(STATE_PRESSED);
if (b != mLastButton) {
mLastButton = b;
buttonIndicator.setText(mLastButton.getText());
}
}
}
}
return true;
}
});
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
}
static boolean isPointWithin(int x, int y, int x1, int x2, int y1, int y2) {
return (x <= x2 && x >= x1 && y <= y2 && y >= y1);
}
}
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Y Cord : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="X Cord : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_toRightOf="#+id/textView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#+id/textView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="B1"
android:textColor="#000000" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button1"
android:text="B2"
android:textColor="#000000" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button2"
android:text="B3"
android:textColor="#000000" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button3"
android:text="B4"
android:textColor="#000000" />
<TextView
android:id="#+id/button_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView4"
android:layout_marginRight="33dp"
android:text="No one"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_indicator"
android:layout_alignBottom="#+id/button_indicator"
android:layout_marginRight="29dp"
android:layout_toLeftOf="#+id/button_indicator"
android:text="Entered: "
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
So this code given above works fine as it recognizes when i swipe my finger from the white space (Relative layout) over any button. But when I swipe from a button to another button, it doesn't work. It doesn't get any coordinates, nor does it sense which button my finger is over. The below image explains best what happens when I swipe from a button to another button.
So how do I get the coordinates while swiping from one button to another?
MainActivity.java
package com.example.touch;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
MyButton b1, b2, b3, b4;
int b1x1, b1x2, b1y1, b1y2;
private TextView xcordview;
private TextView ycordview;
private TextView buttonIndicator;
private RelativeLayout touchview;
private static int defaultStates[];
private Button mLastButton;
private final static int[] STATE_PRESSED = {
android.R.attr.state_pressed,
android.R.attr.state_focused
| android.R.attr.state_enabled };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xcordview = (TextView) findViewById(R.id.textView4);
ycordview = (TextView) findViewById(R.id.textView3);
buttonIndicator = (TextView) findViewById(R.id.button_indicator);
touchview = (RelativeLayout) findViewById(R.id.relativelayout);
b1 = (MyButton) findViewById(R.id.button1);
b2 = (MyButton) findViewById(R.id.button2);
b3 = (MyButton) findViewById(R.id.button3);
b4 = (MyButton) findViewById(R.id.button4);
defaultStates = b1.getBackground().getState();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
touchview.setOnTouchListener(new View.OnTouchListener() {
private boolean isInside = false;
#Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
xcordview.setText(String.valueOf(x));
ycordview.setText(String.valueOf(y));
for (int i = 0; i < touchview.getChildCount(); i++) {
View current = touchview.getChildAt(i);
if (current instanceof Button) {
Button b = (Button) current;
if (!isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
b.getBottom())) {
b.getBackground().setState(defaultStates);
b.getBackground().setAlpha(255);
}
if (isPointWithin(x, y, b.getLeft(), b.getRight(), b.getTop(),
b.getBottom())) {
b.getBackground().setState(STATE_PRESSED);
b.getBackground().setAlpha(150);
b.performClick();
if (b != mLastButton) {
mLastButton = b;
buttonIndicator.setText(mLastButton.getText());
}
}
}
}
return true;
}
});
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
}
static boolean isPointWithin(int x, int y, int x1, int x2, int y1, int y2) {
return (x <= x2 && x >= x1 && y <= y2 && y >= y1);
}
}
MyButton.java
package com.example.touch;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;
public class MyButton extends Button {
public MyButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyButton(Context context) {
super(context);
// // TODO Auto-generated constructor stub
}
#Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
// return super.onTouchEvent(event);
return false;
}
}
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Y Cord : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="X Cord : "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_toRightOf="#+id/textView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#+id/textView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<com.example.touch.MyButton
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="B1"
android:textColor="#000000" />
<com.example.touch.MyButton
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button1"
android:text="B2"
android:textColor="#000000" />
<com.example.touch.MyButton
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button2"
android:text="B3"
android:textColor="#000000" />
<com.example.touch.MyButton
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/button3"
android:text="B4"
android:textColor="#000000" />
<TextView
android:id="#+id/button_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView4"
android:layout_marginRight="33dp"
android:text="No one"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_indicator"
android:layout_alignBottom="#+id/button_indicator"
android:layout_marginRight="29dp"
android:layout_toLeftOf="#+id/button_indicator"
android:text="Entered: "
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

Categories

Resources