Android 视图移动到某个X坐标以外时将消失
我想把视线移到另一个前面。我使用了一个相对布局,以使z顺序如下所示 activity_main.xml:Android 视图移动到某个X坐标以外时将消失,android,Android,我想把视线移到另一个前面。我使用了一个相对布局,以使z顺序如下所示 activity_main.xml: <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="m
<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=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="300dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="200dp"
android:layout_height="300dp"
android:text="."
android:textSize="200dp" />
</RelativeLayout>
但textView2奇怪地消失在某个X坐标之外(好像它位于不可见的第三个视图后面),如下所示:
The beginning:
+-------------------------------+
| |
| +----+ |
| | | |
| | | |
| +----+ |
| |
+-------------------------------+
Moving to the right..
+-------------------------------+
| |
| +----+ |
| | | |
| | | |
| +----+ |
| |
+-------------------------------+
.. and starts to disappear at a certain X.
+-------------------------------+
| |
| +-- |
| | |
| | |
| +-- |
| |
+-------------------------------+
怎么了?您的填充是否正确并不太重要:
android:paddingRight="@dimen/activity_horizontal_margin"
您确定使用setLeft()
是个好主意吗。也许,从布局参数旁边经过会更好
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(event.getX(), 0, 0, 0);
textView2.setLayoutParams(params);
很有效,非常感谢。但是我只是想知道为什么setLeft()在这种情况下不起作用。我不知道为什么,但是文档是明确的,使用这种方法不是一个好主意:
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(event.getX(), 0, 0, 0);
textView2.setLayoutParams(params);