我实际上刚刚开始Android开发,似乎无法将我的文本视图在屏幕上的任何位置对齐
这是我的代码
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="top text"
android:textColor="white"
android:layout_gravity="top|start"
android:textSize="40sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bottom text"
android:textSize="30sp"
android:textColor="white"
android:layout_gravity="bottom|end"/>
</LinearLayout>
我在设计选项卡上获得的"输出"是
返回页首
底
我尝试使用设计拖放文本视图,它增加了tools:layout_editor_absoluteX="138dp"
tools:layout_editor_absoluteY="344dp"
但这不可能是唯一的方法,有人可以告诉我我做错了什么。
好的,
所以我试图对齐屏幕左上角和右下角的文本,我切换到相对布局并添加了一个图像,
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/party"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/hbd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Happy Brithday!!!"
android:textSize="30sp"
android:textColor="#ffffff"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
/>
<TextView
android:id="@+id/sahil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From Sahil"
android:textColor="#ffffff"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textSize="30sp" />
</RelativeLayout>
android:layout_alignParent
职位="true"
帮助实现这一目标。