Android Weight Not Working

2019-08-27 19:53发布

问题:

I have a textview and edittext in a linear layout. Neither view shows up at all if done the way I've seen every example of using weight to set width as a percentage of parent that I can find.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
<TextView
  android:id="@+id/custLabel"
  android:layout_height="wrap_content"
  android:layout_weight=".35"
  android:layout_width="0dip"  
  android:text="Name"/>
<EditText
  android:id="@+id/customer"
  android:layout_height="wrap_content"
  android:layout_weight=".65"
  android:layout_width="0dip"/>
</LinearLayout>

回答1:

Change the orientation of the Layout. You have it vertical and put things there, weighting width!