简体   繁体   English

如何在Android表格布局中对齐微调框和textview?

[英]How to align spinner and textview in android table layout?

I'm creating one table layout with text view and spinner. 我正在使用文本视图和微调器创建一个表布局。

My textview content is too large, so it's wrapped up in my layout. 我的textview内容太大,因此包装在我的布局中。 Whenever the textview having wrapped, the same row spinner also increased the height. 每当textview换行时,同一行微调器也会增加高度。

My code is, 我的代码是

<TableRow 
            android:id="@+id/trConfigPeriodStop" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:weightSum="1" >
            <TextView 
                android:id="@+id/tvConfigPeriodStop"
                android:text="Periodic reporting interval while moving"    
                android:layout_weight="0.5"           
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:textColor="@color/gpsblue"                      
                android:layout_marginLeft="5dp" />
            <Spinner 
                android:id="@+id/spnConfigPeriodStop"
                android:layout_weight="0.5"                
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:entries="@array/periodstop_arrays"
                android:prompt="@string/periodstop_prompt"                                               
                />
        </TableRow>

Suppose I'm changing the layout height in wrap_content in spinner, that time my text view text also hide from view. 假设我要在微调器的wrap_content中更改布局高度,那时候我的文本视图文本也会从视图中隐藏。

How to solve this issue? 如何解决这个问题? Please do the needful. 请只做那些需要的。 Thanks in advance. 提前致谢。

尝试将Spinner和TextView的布局高度都设置为wrap_content。

Try this : 尝试这个 :

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/trConfigPeriodStop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"  
    android:textColor="@color/gpsblue"    
    android:weightSum="1" >

    <TextView
        android:id="@+id/tvConfigPeriodStop"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginLeft="5dp"
        android:layout_weight="0.5"
        android:text="Periodic reporting interval while moving" />

    <Spinner
        android:id="@+id/spnConfigPeriodStop"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:entries="@array/periodstop_arrays"
        android:prompt="@string/periodstop_prompt"  />

</TableRow>

i guess it is because tablerow has android:layout_height="wrap_content" and inner textview has android:layout_height="fill_parent" , so the height of the tablerow will fit to the height of the spinner, that is the only child with fixed and independent height while rendering. 我猜这是因为tablerow具有 android:layout_height =“ wrap_content”,而内部textview具有android:layout_height =“ fill_parent” ,所以tablerow的高度将适合微调器的高度,这是唯一具有固定且独立的子项渲染时的高度。

you will solve it if you change TextView's height also to android:layout_height="wrap_content" 如果将TextView的高度也更改为android,则将解决该问题:layout_height =“ wrap_content”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM