当改变的TextView,在TextView的下方的按钮上的文本向下移动。帮帮我! [英] When changing textview, the text on a button below the textview moves down. Help!

查看:114
本文介绍了当改变的TextView,在TextView的下方的按钮上的文本向下移动。帮帮我!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pretty多少,我有一个充当星号显示一个TextView,当用户点击我做了按钮的针垫。

Pretty much I have a Textview that is acting as a display for asterisks when a user clicks a pin pad of Buttons I made.

按钮具有其文本为中心的,但似乎当我在底部,而不是死点附加的东西TextView的文本属性2号针的布局变为中心。这是XML的一部分的部分:

The buttons have their text centered, but it seems when I append something to the Textview text property the number 2 pin's layout changes to center at the bottom instead of the dead center. This is part part of the xml:

<!-- PIN text -->
<TableLayout>
    <TableRow android:id="@+id/btn_row1"
        android:gravity="center"
        android:layout_marginTop="6dip">
        <!-- password text-->  
        <TextView
            android:id="@+id/txt_pin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:text=""
            android:background="@drawable/txt_background"/>
    </TableRow>
</TableLayout>  
<!-- PIN ends -->
<!-- Header end -->
<!-- PIN button starts -->      
<TableLayout android:id="@+id/table_modes"
    android:layout_marginTop="6dip">
    <!-- First button rows -->  
    <TableRow android:id="@+id/btn_row1"
        android:gravity="center">
        <!-- one button-->  
        <Button android:id="@+id/btn_one"
            android:layout_column="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="3dip"
            android:layout_marginRight="2.5dip"
            android:textColor="#FFFFFF"
            android:text="1"
            android:background="@drawable/button_layout_med" 
            android:onClick="input"/>
        <!-- two Button -->  
        <Button android:id="@+id/btn_two"
            android:layout_column="2"
            android:layout_width="100dip"
            android:layout_height="60dip"
            android:layout_marginLeft="2.5dip"
            android:layout_marginRight="2.5dip"
            android:gravity="center"
            android:textColor="#FFFFFF"
            android:text="2"
            android:background="@drawable/button_layout_med" 
            android:onClick="input"/>
        <!-- 3 button -->  
        <Button android:id="@+id/btn_three"
            android:layout_column="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2.5dip"
            android:layout_marginRight="3dip"
            android:textColor="#FFFFFF"
            android:text="3"
            android:background="@drawable/button_layout_med" 
            android:onClick="input"/>
    </TableRow>
    <!-- First row ends -->
 <!-- Rows continue down 3 more then a submit and back button -->

接下来的部分是java code代表的OnClick:

The next part is the java code for OnClick:

public void input(View v){
            Button i = (Button) v;
    TextView tv_pin = (TextView) findViewById(R.id.txt_pin);


    while(view_pin.length() < 10){
        pin.append(i.getText().toString());
        view_pin.append('*');
        tv_pin.setText(view_pin.toString());
        break;
    }

}

在哪里引脚和view_pin是私有的静态变量。

Where pin and view_pin are private static variables.

推荐答案

要解决这个问题,我只是不得不改变XML code的高度和宽度的第二个按钮为WRAP_CONTENT,而不是给他们一个静态值。

To fix this problem I simply had to change the XML code for height and width for the second button to "wrap_content" instead of giving them a static value.

<!-- two Button -->  
<Button android:id="@+id/btn_two"
    android:layout_column="2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="2.5dip"
    android:layout_marginRight="2.5dip"
    android:gravity="center"
    android:textColor="#FFFFFF"
    android:text="2"
    android:background="@drawable/button_layout_med" 
    android:onClick="input"/>

这篇关于当改变的TextView,在TextView的下方的按钮上的文本向下移动。帮帮我!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆