开发者

Merge two layout into one

开发者 https://www.devze.com 2023-03-29 06:28 出处:网络
Is it possible to merge two l开发者_如何学编程ayout into one. Suppose i have two TextView of username and password in first layout vertically and two EditText in the second layout vertically. After me

Is it possible to merge two l开发者_如何学编程ayout into one. Suppose i have two TextView of username and password in first layout vertically and two EditText in the second layout vertically. After merging this two layout the final layout will contain two row's of TextView and EditText.

Oh one thing left is that when merging the first layout move from left to right and the second layout will move from right to left.


You have options of doing this by applying TranslateAnimation. Applying Animation it seem that two layout is merging and making one. Hope the following code will help you.

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);
0

精彩评论

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