Android 将文本视图左对齐并居中对齐
我究竟如何做到这一点?我试着在android:layout|u gravity center | left和android:gravity center | left之间胡闹,但似乎都不管用。我使用的是可展字符串有什么区别吗 提前谢谢 我的布局。。它是ID状态为的文本视图Android 将文本视图左对齐并居中对齐,android,layout,textview,alignment,center,Android,Layout,Textview,Alignment,Center,我究竟如何做到这一点?我试着在android:layout|u gravity center | left和android:gravity center | left之间胡闹,但似乎都不管用。我使用的是可展字符串有什么区别吗 提前谢谢 我的布局。。它是ID状态为的文本视图 <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_p
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Main layout -->
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f2f2f2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"><![CDATA[
>
]]>
<include
layout="@layout/actionbarmenu"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="0.64" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="5dp"
android:background="#FAFAFA"
android:gravity="center|left"
android:text="Notfallübersicht"
android:textColor="#c9c9c9"
android:textSize="18sp" />
<EditText
android:id="@+id/Notfall"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_weight="0.36"
android:background="@drawable/round_grey"
android:ellipsize="end"
android:gravity="center"
android:hint="Notfall-Code Eingabe"
android:inputType="text"
android:paddingLeft="6dp"
android:singleLine="true"
android:textAllCaps="false"
android:textColor="#585858"
android:textColorHint="#c9c9c9"
android:textCursorDrawable="@drawable/black_cursor" />
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.70" />
<TextView
android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3.63"
android:gravity="center"
android:textColor="#6f7070"
android:textSize="20sp"
android:visibility="visible" />
<TextView
android:id="@+id/abgemeldet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10.08"
android:text="Bitte melde dich mit deinen Pengueen Log-In Daten an, um die App zu aktivieren. "
android:textSize="24sp" />
<TextView
android:id="@+id/user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="0.60"
android:text="Angemeldet als :"
android:textSize="14sp"
android:visibility="invisible" />
<TextView
android:id="@+id/angemeldet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1.09"
android:text="Letzte Abfrage vor 1 Minute"
android:textSize="14sp"
android:textStyle="bold"
android:visibility="invisible" />
<Button
android:id="@+id/button"
style="@style/Widget.AppCompat.Button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4697c4"
android:text="Anmleden"
android:textColor="#ffffff"
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.74">
<!-- This could be your fragment container, or something -->
<FrameLayout
android:id="@+id/contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomBar" />
<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app2:bb_activeTabAlpha="1"
app2:bb_activeTabColor="#ffffff"
app2:bb_inActiveTabAlpha="0.6"
app2:bb_inActiveTabColor="#ffffff"
app2:bb_tabXmlResource="@xml/bottombar_tabs" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</FrameLayout>
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#51aadd"
android:choiceMode="singleChoice"
android:divider="@drawable/list_divider"
android:footerDividersEnabled="false"
android:headerDividersEnabled="true"
android:scrollbars="none" />
</android.support.v4.widget.DrawerLayout>
]]>
您需要在所需的文本视图中使用此选项:
android:layout_width="wrap_content"
android:gravity="left"
android:layout_gravity="center_horizontal"
- android:gravity设置视图内容的重力
- android:layout_gravity设置视图相对于其父视图的重力
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
将xml代码发布到
抽屉布局中
,您只需要有一个视图
,而不是抽屉。任何非抽屉视图
被拉伸以填充抽屉布局
,其布局_重力
值被忽略。现在,整个文本左对齐,但不居中