【问题标题】:Making a view in layout keep its size when another grows当另一个视图增长时,使布局中的视图保持其大小
【发布时间】:2018-04-12 13:38:20
【问题描述】:

我想实现这样一个简单的布局:

|标题 |日期 |

两个视图都应环绕其内容并应与左侧对齐。如果内容不适合一行,则标题应向右增长并在末尾变为椭圆形。日期应该在标题的右侧,当标题很大并且日期移动到右侧时,保持它的宽度而不是椭圆。

我无法达到第二个要求。当标题增长并且日期到达屏幕右侧时,日期总是椭圆形的。我尝试过 LinearLayout、RelativeLayout 和 ConstraintLayout。

谁能给我一个例子来说明如何做到这一点?

【问题讨论】:

    标签: android android-layout android-relativelayout android-constraintlayout


    【解决方案1】:

    我不知道我是否收到您的问题,但您可以简单地使用 LinearLayoutweight例如:-

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal"
        android:weightSum="1">
    
        <TextView
            android:id="@+id/tv_1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight=".5" // or whatever you want
            android:background="?android:attr/selectableItemBackground"
            android:gravity="center"
            android:padding="10dp"
            android:text="TITLE" />
    
        <TextView
            android:id="@+id/tv_2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight=".5" // or whatever you want
            android:background="?android:attr/selectableItemBackground"
            android:gravity="center"
            android:padding="10dp"
            android:text="Date" />
    
    </LinearLayout>
    

    【讨论】:

    • 这会将水平空间分成两个固定部分,我不希望那样。
    猜你喜欢
    • 1970-01-01
    • 2017-07-01
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多