Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 文本视图在拖动时自动对齐_Java_Android_Xml - Fatal编程技术网

Java 文本视图在拖动时自动对齐

Java 文本视图在拖动时自动对齐,java,android,xml,Java,Android,Xml,当我将文本视图拖动到屏幕的右侧时,它会自动“居中”对齐,但我不想自动对齐文本视图。(如果我将文本视图拖动到右侧,如果文本视图部分隐藏,我可以这样做)。我该怎么办 这是我的密码 XML代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linear"

当我将文本视图拖动到屏幕的右侧时,它会自动“居中”对齐,但我不想自动对齐文本视图。(如果我将文本视图拖动到右侧,如果文本视图部分隐藏,我可以这样做)。我该怎么办

这是我的密码

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Test1" />


    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Test2" />
</RelativeLayout>

试试这个,以保持正确的对齐

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Test1"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />


    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Test2"
        android:layout_below="@+id/tv1"
        android:layout_marginTop="34dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>


它不工作。。当我使用参数“align_parent top或right或bottom”时,我不能拖动任何位置。你可以更具体地说,你到底想要什么?我想在屏幕上的任何位置移动我的文本视图,而不自动对齐。然后你应该考虑布局中的Fragmnet。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Test1"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />


    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Test2"
        android:layout_below="@+id/tv1"
        android:layout_marginTop="34dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>