Note that there are some explanatory texts on larger screens.

plurals
  1. POMoving textview through whole screen
    primarykey
    data
    text
    <p>I have developed an app which shows the time in a full screeen. The hours minutes and seconds are displayed in the middle of the screen. So my objective is, when I long click any of the textviews be able to scrool it through all the screen, and place it where I want...</p> <p>I tried to find a proper code to apply to my app, and I found a code which makes text to image an then move that image. But the problem is, texts are updating each a second, so I think creating images each second is not a good idea...</p> <p>Anyone knows a method to be able to move textviews through all the screen??? This is one of my textviews</p> <pre><code>private TextView txtHour; txtHour = (TextView)findViewById(R.id.TxtHour); txtHour.setOnLongClickListener(new OnLongClickListener{ .... </code></pre> <p>I dont know what to add to this.... :( Please HELP!</p> <p>EDIT: According to first answer, should my code look like this?</p> <pre><code> txtHour.setOnLongClickListener(new OnLongClickListener() { public void onLongClick(View v){ public void drag(MotionEvent event, View v) { RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) v.getLayoutParams(); switch(event.getAction()) { case MotionEvent.ACTION_MOVE: { params.topMargin = (int)event.getRawY() - (v.getHeight()); params.leftMargin = (int)event.getRawX() - (v.getWidth()/2); v.setLayoutParams(params); break; } case MotionEvent.ACTION_UP: { params.topMargin = (int)event.getRawY() - (v.getHeight()); params.leftMargin = (int)event.getRawX() - (v.getWidth()/2); v.setLayoutParams(params); break; } case MotionEvent.ACTION_DOWN: { v.setLayoutParams(params); break; } } }}); </code></pre> <p>EDIT 2: finnaly this is result code, is this ok?</p> <pre><code> package com.iamaner.T2Speech; //imports public class MAINActivity extends Activity{ private TextView txtHour; private TextView txtMinutes; private TextView txtSeconds; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtHour = (TextView)findViewById(R.id.TxtHour); txtMinutes = (TextView)findViewById(R.id.TxtMinute); txtSeconds = (TextView)findViewById(R.id.TxtSeconds); txtHour.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub drag(event, v); return false; }}); } public void drag(MotionEvent event, View v) { FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) v.getLayoutParams(); switch(event.getAction()) { case MotionEvent.ACTION_MOVE: {params.topMargin = (int)event.getRawY() - (v.getHeight()); params.leftMargin = (int)event.getRawX() - (v.getWidth()/2); v.setLayoutParams(params); break;} case MotionEvent.ACTION_UP: {params.topMargin = (int)event.getRawY() - (v.getHeight()); params.leftMargin = (int)event.getRawX() - (v.getWidth()/2); v.setLayoutParams(params); break;} case MotionEvent.ACTION_DOWN: {v.setLayoutParams(params); break;} }} } </code></pre> <p>And this framelayout</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/your_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:id="@+id/TxtHour" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15mm" android:textColor="#000000"/&gt; &lt;TextView android:id="@+id/TxtPoints1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/separator" android:textSize="15mm" android:textColor="#000000" android:layout_gravity="center" android:gravity="center"/&gt; &lt;TextView android:id="@+id/TxtMinute" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15mm" android:textColor="#000000" android:layout_gravity="center" android:gravity="center" /&gt; &lt;TextView android:id="@+id/TxtPoints2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/separator" android:textSize="15mm" android:textColor="#000000" android:layout_gravity="center" android:gravity="center"/&gt; &lt;TextView android:id="@+id/TxtSeconds" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15mm" android:textColor="#000000" android:layout_gravity="bottom|right" /&gt; &lt;/FrameLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload