【问题标题】:Android floating fixed width text effectAndroid浮动定宽文字效果
【发布时间】:2013-12-13 16:20:10
【问题描述】:

我不知道如何命名这种效果,但这是我不想实现的。我想知道是否可以仅使用 xml 布局来做到这一点。

我有 2 个文本视图。 Text_View_AText_View_B

Text_View_A 启用了椭圆大小。

我希望Text_View_B 始终位于Text_View_A 的右侧

但也可以让Text_View_A 位于Text_View_B 的左侧,并且如果没有足够的空间放置它,椭圆大小将启动。

是否可以仅通过布局来实现?还是我必须手动计算?

【问题讨论】:

标签: android android-layout


【解决方案1】:

您可以使用相对布局并将Text_View_B设置为parentRight true并设置Text_View_A toLeftText_View_B.

    <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content">
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Text_View_B"
        android:layout_alignParentRight="true" />

    <TextView android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:id="@+id/Text_View_A"
        android:layout_toLeftOf="@id/Text_View_B" />
</RelativeLayout>

【讨论】:

  • 位将始终使 Text_View_B 粘在屏幕右侧,而我需要它粘在 Text_View_A 上。
【解决方案2】:
<LinearLayout>
      <TextView android:id="@+id/textview_1" android:weight="7" />
      <TextView android:weight="3"/>
</LinearLayout>

textview_1.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
textview_1.setMaxWidth(textview_1.getMeasuredWidth());

试试这个。

【讨论】:

    猜你喜欢
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多