I am learning to code in Eclipse for Android. I googled and understood that View.OnLongClickListener can be used to call a method when the user long presses in the application. However, I am stuck at coming at a solution to make the TextView to shift it based on the exact location where the user long presses.
I have implemented the condition to check for a long press from the user. Any idea on how to make the TextVIew appear where the user long presses? I want the TextView to appear exactly where the user long presses.
findViewById(R.id.myimage).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showNameInCustomPosition();// Method to call to when user long presses
return false;
}
});
Update: I am not getting the text to move, but when I click on the edge of the screen, the text is partially displayed that it goes outside the scope of the screen. Can anyone suggest how to avoid this? This is my Layout properties now.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myimage"
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"
android:background="@drawable/shrinivas"
android:onClick="onClick"
android:clickable="true"
tools:context="com.example.hello.MainActivity" >
<TextView
android:id="@+id/shownamecenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_text2" />
<TextView
android:id="@+id/shownamecustom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_gravity="fill"
android:text="@string/my_text" />
</RelativeLayout>
The one with id shownamecustom is the one causing provblems.