Android在两个分隔符之间水平对齐文本视图
以下是我努力实现的目标: 以下是我如何尝试的:Android在两个分隔符之间水平对齐文本视图,android,android-layout,Android,Android Layout,以下是我努力实现的目标: 以下是我如何尝试的: <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/padd_loading_btn" android:layout_marginBott
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padd_loading_btn"
android:layout_marginBottom="@dimen/padd_loading_btn" >
<View
android:layout_width="65dp"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/orLoginWithEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/orlogin_withEmail"
android:textSize="12sp" />
<View
android:layout_width="65dp"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:background="@android:color/darker_gray" />
</LinearLayout>
对于我的高清显示器来说,这看起来不错,但对于其他显示器来说,这看起来很糟糕
如何使文本尽可能多地换行,然后使分隔符在两侧均匀对齐
p、 当然,我可以设置一个相对的布局和内部,以放置一个分隔符来填充宽度,并在文本视图上方添加白色背景和填充,但我认为这不是最好的解决方案。尝试这样做
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padd_loading_btn"
android:layout_marginBottom="@dimen/padd_loading_btn" >
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/orLoginWithEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical"
android:text="@string/orlogin_withEmail"
android:textSize="12sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:background="@android:color/darker_gray" />
</LinearLayout>
尝试使用框架布局,记住将后视图的宽度设置为“匹配父视图”,将TextView的背景设置为null或白色,并将TextView paddingLeft和paddingRight设置为达到所需效果
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padd_loading_btn"
android:layout_marginBottom="@dimen/padd_loading_btn" >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/orLoginWithEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_gravity="center"
android:background="@android:color/white"
android:text="@string/orlogin_withEmail"
android:textSize="12sp" />
</FrameLayout>
您可以尝试使用以下代码,您可以将文本视图更改为视图
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:background="#cccccc" />
<TextView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:gravity="center_horizontal"
android:background="#ffffff"
android:text="Hello Android" />
<TextView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:background="#cccccc" />
</LinearLayout>
这是输出
这正是我想要实现的目标。非常感谢。这对我有用,所以谢谢你!但我认为您应该将:
android:orientation=“horizontal”
添加到LinearLayout