android - 将两个布局合并为一个

标签 android android-edittext textview

是否可以将两个布局合并为一个。假设我在第一个垂直布局中有两个用户名和密码的 TextView,在第二个垂直布局中有两个 EditText。合并这两个布局后,最终布局将包含两行 TextView 和 EditText。

哦,还有一件事是合并第一个布局时从左向右移动,第二个布局将从右向左移动。

最佳答案

您可以选择通过应用 TranslateAnimation 来执行此操作。应用动画似乎两个布局正在合并并成为一个。希望以下代码对您有所帮助。

layout.xml...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
 >
<Button
android:id="@+id/btn1"
android:text="Button 1"
android:layout_width="fill_parent" 
android:layout_height="45dip" 
android:layout_marginTop="10dip"
/>

<Button
android:id="@+id/btn2"
android:text="Button 2"
android:layout_width="fill_parent" 
android:layout_height="45dip"
android:layout_marginTop="10dip" />

<Button
android:id="@+id/btn3"
android:text="Button 3"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="10dip"
/>

<Button
android:id="@+id/btn4"
android:text="Button 4"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="10dip"
/>

MyActivity.java

    Button b1, b2, b3, b4;
    TranslateAnimation left, right;

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    left = new TranslateAnimation(-480, 10, 0, 10);
    right= new TranslateAnimation( 480, 10, 0, 10);

    left.setDuration(2000);
    right.setDuration(2000);

    left.setRepeatCount( 1 );
    right.setRepeatCount( 1 );

    b1 =(Button)findViewById( R.id.btn1);
    b2 =(Button)findViewById( R.id.btn2);
    b3 =(Button)findViewById( R.id.btn3);
    b4 =(Button)findViewById( R.id.btn4);

    b1.startAnimation(left);
    b2.startAnimation(right);
    b3.startAnimation(left);
    b4.startAnimation(right);

关于android - 将两个布局合并为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7133022/

相关文章:

android - 布局 TextView 提示并不总是显示

android - 动画监听器和 Intent

java - 在不丢失多行功能的情况下为 EditText 设置输入类型?

android - 我如何在Android编程中获取TextView的默认值?

android TextView 值

android - 从 Android 中的服务更新 Activity 中的 TextView?

java - 创建随机放置的按钮,不超过屏幕尺寸

android - ProgressBar 在 FrameLayout 之上

Android:键入文本时 EditText 不更新

android - AlertDialog 在关闭时专注于 EditText..导致键盘出现..该怎么办?