我仍然是一个Android noob,原谅我,如果这很简单,我只是没有看到它.
视图中有两个文本部分水平跨越整个宽度,但只有一行文本高.左侧必须始终显示完整,但不应占用超出其需要的水平空间.应将左侧推过右侧并填满屏幕宽度的其余部分.如果右侧文本小于此宽度,则文本应水平右对齐.如果文本大于宽度,则应水平滚动.
右侧的文本将经常更新,并应在应用程序告诉它时向上滑动新文本(解释布局中的TextSwitcher).
我尝试了两种不同的布局样式.在这两种情况下,我可以让左侧"推"布局,右侧滚动,但我无法弄清楚如何让右侧对齐.它始终保持对齐.这是一张显示正在发生的事情的图片......
http://img10.imageshack.us/img10/5599/androidlayout.png
另外(但不太重要),在我的布局代码中,我在TextViews上有android:fadingEdge ="none",但滚动时左右两侧仍有褪色边缘.这是为什么?
这是我创建的两个布局,它们产生了显示的结果,但不是我想要的结果.
使用水平LinearLayout ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayoutStatusBar"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2px"
android:background="#555555"
>
<TextView
android:id="@+id/TextViewTimer"
android:textSize="18px"
android:textColor="#FFFFFF"
android:layout_gravity="left"
android:layout_weight="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0px"
android:layout_marginRight="3px"
android:text="Left Side"
>
</TextView>
<TextSwitcher
android:id="@+id/TextSwitcherDetails"
android:inAnimation="@anim/push_up_in"
android:outAnimation="@anim/push_up_out"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="3px"
android:layout_marginRight="0px"
>
<TextView
android:id="@+id/TextViewDetails1"
android:textSize="18px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadingEdge="none"
android:text="Right Side 1"
>
</TextView>
<TextView
android:id="@+id/TextViewDetails2"
android:textSize="18px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadingEdge="none"
android:text="Right …Run Code Online (Sandbox Code Playgroud)