开发者

Layout problems. Android

I have some behaviour of my layout. I give two of them, very similar to each other. Only one difference is the width attribute of the textviews.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="bottom">
    <LinearLayout  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:isScrollContainer="true"
        android:gravity="center"
        android:background="@color/black">
        <LinearLayout
            android:id="@+id/tabs"
            android:layout_width="0dp" 
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:background="@color/black"
            android:layout_weight="1">                      
            <TextView   
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Einstellungen"
                android:drawableTop="@drawable/selector_settings" 
                android:id="@+id/main_menu_button_connection" 
                android:gravity="center" 
                android:textAppearance="?android:attr/textAppearanceMedium" 
                android:textSize="10px">
            </TextView>     
            ...
            <TextView   
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Suche"
                android:drawableTop="@drawable/selector_search" 
                android:id="@+id/main_menu_button_connection" 
                android:gravity="center" 
                android:textAppearance="?android:attr/textAppearanceMedium" 
                android:textSize="10px">
            </TextView>
        </LinearLayout>             
    </LinearLayout>
</LinearLayout>

If layout_width is set to wrap content, I get following layout results:

Layout problems. Android

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="bottom">
    <LinearLayout  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:isScrollContainer="true"
        android:gravity="center"
        android:background="@color/black">
        <LinearLayout
            android:id="@+id/tabs"
            android:layout_width="0dp" 
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:background="@color/black"
            android:layout_weight="1">                      
            <TextView   
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:text="Einstellungen"
                android:drawableTop="@drawable/selector_settings" 
                android:id="@+id/main_menu_button_connection" 
                android:gravity="center" 
                android:textAppearance="?android:attr/textAppearanceMedium" 
           开发者_StackOverflow社区     android:textSize="10px">
            </TextView>     
            ...
            <TextView   
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:text="Suche"
                android:drawableTop="@drawable/selector_search" 
                android:id="@+id/main_menu_button_connection" 
                android:gravity="center" 
                android:textAppearance="?android:attr/textAppearanceMedium" 
                android:textSize="10px">
            </TextView>
        </LinearLayout>             
    </LinearLayout>
</LinearLayout>

If layout_width is set to a value instead (here 70dp), my layout looks so, I want it to have:

Layout problems. Android

Can anybody explain me, why?!

Is there some solution avoiding to set a constant width and still having layout result like at the second picture?!

Thank you in advance


You probably want to give each TextView an equal layout weight such as android:layout_weight="1" and a width of fill_parent. Also, don't give a weight for the tabs linear layout. Also, while I don't really know what's going on later in the layout file, having three nested LinearLayouts seems like it might be wasteful. Maybe you can get rid of one of them?


I recommend starting over and using the eclipse designer view or use droiddraw to create the layout, especially since there are recent improvements to the layout editor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜