Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.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
布局重力问题:android:Layout_Gravity=";完";_Android_Android Layout - Fatal编程技术网

布局重力问题:android:Layout_Gravity=";完";

布局重力问题:android:Layout_Gravity=";完";,android,android-layout,Android,Android Layout,我是刚开始学习Android Studio的,在这里遇到了一些麻烦。在这段代码的解释中,我应该看到Hello world贴在右边,但他不想从左边移动。以下是预期结果: 还有我吃的东西 将android:orientation=“vertical”添加到您的线性布局中。默认方向为水平。您可以将文本视图重力设置为右侧,并使线性布局方向水平,如下所示 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

我是刚开始学习Android Studio的,在这里遇到了一些麻烦。在这段代码的解释中,我应该看到Hello world贴在右边,但他不想从左边移动。以下是预期结果: 还有我吃的东西



android:orientation=“vertical”
添加到您的
线性布局中。默认方向为水平。

您可以将文本视图重力设置为右侧,并使线性布局方向水平,如下所示

<LinearLayout 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:visibility="visible"
tools:context=".MainActivity"
orientation="horizontal">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:gravity="right"
    android:text="Hello World!" />

</LinearLayout>

尝试以下代码:-

<LinearLayout 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:visibility="visible"
android:orientation="horizontal">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:gravity="end"
    android:text="Hello World!" />

</LinearLayout>

<LinearLayout 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:visibility="visible"
android:orientation="horizontal">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:gravity="end"
    android:text="Hello World!" />

</LinearLayout>