我如何完全实现这一目标?我试着用android:layout_gravity center | left和android:gravity center | left和none似乎工作。我使用spannable字符串会有什么不同吗?
Here is what I have right now and what I want to achive. I want my Text to align to the red line
提前致谢。
我的布局..这是具有ID状态
的TextView
<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>
答案 0 :(得分:0)
您需要在所需的文字视图中使用此内容:
android:layout_width="wrap_content"
android:gravity="left"
android:layout_gravity="center_horizontal"
答案 1 :(得分:0)
您可以看到Difference between gravity and layout_gravity on Android
android:TextView的重力默认值是左边的,它就是你想要的,你只需要改变layout_gravity。
当设置TextView android:layout_gravity =“center_horizontal”时,你应该设置android:layout_width =“wrap_content”,而不是'match_parent'。
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"