如何让textView1占用所有其他空间?

时间:2014-06-06 06:10:34

标签: android

我希望imageButton1位于屏幕左侧,btnOn位于屏幕左侧,我希望textView1占用所有其他空间。

我该怎么办?我已经设置了android:layout_weight =" 1",但它不会产生任何影响。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"    
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/border_ui"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="myID"
        ads:loadAdOnCreate="false" />    

     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:gravity="center|center_horizontal|center_vertical"
        android:layout_marginLeft="10px"
        android:layout_marginRight="10px"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
             android:gravity="center_vertical"
             >

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@android:drawable/sym_def_app_icon" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="0dip"
                android:layout_height="wrap_content"             
                android:layout_weight="1"
                android:text="Text 123"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageView
                android:id="@+id/btnOn"
                android:layout_width="80dp"
                android:layout_height="40dp"
                android:src="@drawable/btnon"

                android:visibility="visible" >
            </ImageView>



        </LinearLayout>        


     </LinearLayout>  

</LinearLayout>

3 个答案:

答案 0 :(得分:2)

使用相对布局并将父对齐对齐,并将TextView类型更改为邮政地址。它将创建textArea。

答案 1 :(得分:0)

您需要单独为布局内的所有视图提供权重。试试:

     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
       android:gravity="center_vertical">

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:src="@android:drawable/sym_def_app_icon" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="0dp"
            android:layout_weight="0.6"
            android:layout_height="wrap_content"             
            android:text="Text 123"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/btnOn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:src="@drawable/btnon"
            android:visibility="visible" />
     </LinearLayout>

答案 2 :(得分:0)

I have modified your code Try this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"    
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/border_ui"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="myID"
        ads:loadAdOnCreate="false" />    

     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:gravity="center|center_horizontal|center_vertical"
        android:layout_marginLeft="10px"
        android:layout_marginRight="10px"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical" >

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@android:drawable/sym_def_app_icon" />

            <ImageView
                android:id="@+id/btnOn"
                android:layout_width="80dp"
                android:layout_height="40dp"
                android:src="@drawable/btnon"
                android:visibility="visible" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="0dip"
                android:layout_height="match_parent"             
                android:layout_weight="1"
                android:text="Text 123"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>        

     </LinearLayout>  
</LinearLayout>
You just need to put imageview after imagebutton so it will displayed at left and at last your textview will displayed and accupies all remaining space.