Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

android - Layout weight isn't distributing equally when there is lot of space left

I'm messing around with Android Studio documents about layout_weight and I'm trying to get use to it. But something weird happens, I assume that if I give some elements value and, The rest will be calculated and distributed equally to which elements have layout_weight specified. Somehow the result make me confuse as There was lots of space left but the TextView decided to get super small and super long.

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="horizontal"  >

    <ImageView
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:scaleType="centerCrop"
        android:src="@drawable/ocean" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pebble Beach"
        android:background="#FF0"
        android:textAppearance="?android:textAppearanceMedium" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="California"
        android:background="#FF0"
        android:textAppearance="?android:textAppearanceSmall" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="10 miles away"
        android:background="#FF0"
        android:textAppearance="?android:textAppearanceSmall" />

</LinearLayout>

enter image description here

question from:https://stackoverflow.com/questions/66050880/layout-weight-isnt-distributing-equally-when-there-is-lot-of-space-left

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In Android Studio Goto "File" then select "Invalidate cache/Restart".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...