Mic*_*ł K 8 android android-layout
我有一个布局,需要将其中一个视图放在中心.这很简单.问题是我还有一些其他视图需要定位到屏幕顶部.
问题:如果有足够的空间,它看起来没问题,但是当屏幕太小时,顶部和中心元素重叠.
问题:如果屏幕很小,如何将"居中"元素按下?
原来的布局非常复杂,我准备了一个例子:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/theOneAtTheTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some long text which may overlap the lower view. Some long text which may overlap the lower view."
android:layout_alignParentTop="true"
/>
<TextView
android:id="@+id/theOneInTheMiddlep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some long text which may overlap the upper view. Some long text which may overlap the upper view. "
android:layout_centerInParent="true"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是一个小模拟.中间的图片显示了它在小屏幕上的外观,并且两侧的图片显示了所需的情况.
好吧,我要彻底改变这个答案。如果所需的对齐方式是垂直的,您可以将代码放入relativelayout中,它将_fill_parent_并且位于OneAtTheTop下方。在其中,您可以放置想要垂直居中对齐的视图。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/theOneAtTheTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Some long text which may overlap the lower view. Some long text which may overlap the lower view." />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/theOneAtTheTop" >
<TextView
android:id="@+id/theOneInTheMiddlep"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Some long text which may overlap the upper view. long text which may overlap the upper view. Some long text which may overlap the upper view. " />
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你
归档时间: |
|
查看次数: |
814 次 |
最近记录: |