Put two textviews side by side in a layout

前端 未结 4 1957
一整个雨季
一整个雨季 2021-02-01 17:28

I have two textviews i need to put side by side in a layout and I have to respect two rules:

  • Textview2 needs always to be displayed entirely.

  • T

4条回答
  •  暖寄归人
    2021-02-01 18:12

    Wrap the two TextViews in a LinearLayout. Assign a layout weight of 0 to textview2 and a layout weight of 1 to textview2.

    See here for more info: Linear Layout Weight

    If you play with the example below you'll see that the LinearLayout first allocates space to textview2 (with weight 0) and then allocates whatever remains to textview1 (with weight 1). If there is insufficient space to accommodate both TextViews, textview1 will be ellipsized first. In the example below textview2 will only ever become ellipsized if the LinearLayout is smaller than the size of textview2 itself. Assign a specific layout width to the FrameLayout and see what happens.

    
    
    
        
    
            
    
            
        
    
    
    

提交回复
热议问题