如何在android中对齐文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2750798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to align text in android
提问by ryan
I want to align my text at the bottom left in android.
我想在android的左下角对齐我的文本。
回答by synic
If you want to align the text in your TextView to the bottom left, use android:gravity="bottom|left"
. If you want to align the TextView to the bottom left of it's container, use android:layout_gravity="bottom|left"
.
如果要将 TextView 中的文本与左下角对齐,请使用android:gravity="bottom|left"
. 如果要将 TextView 与其容器的左下角对齐,请使用android:layout_gravity="bottom|left"
.
I suspect that you're mis-communicating your true intentions, here, though. You want to align some text to the bottom left of what? The screen? The text's container?
不过,我怀疑你在这里传达了错误的真实意图。您想将一些文本与什么内容的左下角对齐?屏幕?文本的容器?
Please try to be more specific with your question.
请尝试更具体地回答您的问题。
Bottom left of the screen:
屏幕左下角:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="bottom|left"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text"/>
</FrameLayout>
回答by Janusz
I would recommend a Relative layout.
我会推荐一个相对布局。
Your view would look like this:
您的视图将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text aligned bottom left"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
回答by Leontin Groza
android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"
Must be written inside your TextView
必须写在你的 TextView 中