【发布时间】:2011-03-29 20:26:03
【问题描述】:
我有一个使用 TextView 动态填充的 HorizontalScrollView。有时有一个、两个、三个或更多元素。我正在寻找的是一种使项目居中而不考虑元素数量的方法。
例如,只有一个元素:
| --------- MenuA --------- |
有两个元素:
| ---- MenuA --- MenuB ---- |
包含三个元素:
| - MenuA - MenuB - MenuC - |
有五个元素(MenuD 和 MenuE 被隐藏):
| MenuA - MenuB - MenuC - Me|
更新:这是一个带有两个菜单的简单布局。如何使 MenuA 和 MenuB 居中?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView android:text="MenuA" android:id="@+id/textView1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="MenuB" android:id="@+id/textView2"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
【问题讨论】:
-
所以你的
ScollView是水平的(比屏幕宽),项目是屏幕居中的? -
是的,我的 HorizontalScrollView 是水平的,项目应该水平居中
标签: android horizontalscrollview