0

私は次のようなAndroidのテーブルレイアウトを持っています:

1) Row == IMAGEVIEW | TEXTVIEW
2) Row == IMAGEVIEW | SPINNER

次に、TEXTVIEW/SPINNER を切り替える必要があります。2列目は1列目、1列目は2列目です。

少しアニメーションもあれば最高です。Viewswitcher と Viewflipper を見てきましたが、これは私が探しているものではないようです。これを機能させる方法を知っている人はいますか?

私のレイアウト(その一部)は次のようになります。

<TableRow>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/left_layout_controlls"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
                <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="wrap_content" 
                    android:stretchColumns="*"
                    android:id="@+id/top_controlls"
                    android:layout_height="wrap_content">

                    <TableRow>
                        <ImageView
                           android:id="@+id/fromCountry_img" 
                           android:src="@drawable/tc_rt_from"
                           android:layout_width="wrap_content"
                           android:layout_gravity="center_horizontal"
                           android:layout_height="fill_parent"
                           />

                        <TextView
                            android:id="@+id/fromCountry"
                            android:layout_marginTop="2px"
                            android:layout_marginLeft="2px"
                            android:background="@drawable/round_edges_main_controll"

                            android:layout_marginRight="2px"
                            android:layout_height="38px"
                            android:layout_width="160dip"/>
                        </TableRow>
                     </TableLayout>

                    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        android:layout_width="wrap_content" 
                        android:stretchColumns="*"
                        android:layout_below="@id/top_controlls"
                        android:layout_height="wrap_content">
                        <TableRow>
                             <ImageView 
                               android:src="@drawable/tc_rt_to"
                               android:layout_width="wrap_content"
                               android:layout_gravity="center_horizontal"
                               android:layout_height="fill_parent"
                               android:layout_below="@id/fromCountry_img"
                               />

                            <Spinner 
                                android:id="@+id/toCountry"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="2px"
                                android:layout_marginBottom="2px"
                                android:layout_marginRight="2px"
                                android:layout_width="160dip"
                                android:layout_weight="1"
                                android:drawSelectorOnTop="true"/>
                        </TableRow>
                    </TableLayout>

アップデート:

このようにコントロールを切り替えようとしましたが、アニメーションは機能しますが、アニメーションが終了すると、コントロールは元の位置に戻ります。

理由はありますか?

LinearLayout layout1 = ((LinearLayout) DataHolder.activityHolder.findViewById(R.id.top_controll));
            LinearLayout layout2 = ((LinearLayout) DataHolder.activityHolder.findViewById(R.id.bottom_controll));
DataHolder.activityHolder.findViewById(R.id.toCountry));
TranslateAnimation a = new TranslateAnimation(
Animation.ABSOLUTE,0,Animation.ABSOLUTE,0,
Animation.ABSOLUTE,0,Animation.ABSOLUTE, 40);
a.setDuration(1200);

TranslateAnimation b = new TranslateAnimation(
Animation.ABSOLUTE,0,Animation.ABSOLUTE,0,
Animation.ABSOLUTE,0,Animation.ABSOLUTE, -40);
b.setDuration(1200);

layout1.startAnimation(a);
layout2.startAnimation(b);
4

3 に答える 3

0

これを行う最も簡単な方法は、Spinnerがある場所にTextViewとTextViewがある場所に(コンテナ内では発生しない)可視性のあるSpinnerを使用することです。次に、表示を切り替えるだけです。この解決策は実用的ではありません。

于 2011-07-27T18:04:15.313 に答える
0

grmpf、

動作するようになりました。ありがとう。エラーは、私がこれをフロゴットしたことでした:

setFillAfter(true);

これにより、アニメーションが終了した後も変更が保持されます

于 2011-07-29T09:20:12.933 に答える
0

正直なところ、この状況で TableLayout を使用するのは実用的ではないと思います。あなたが提供したビューは TableLayout が最も実用的であることを示唆していますが、TableLayout はかなり静的になるように設計されています。TableLayout 内の TableRows を削除またはアニメーション化する方法があることを知りません。

これを次のように使用することをお勧めします。

<LinearLayout android:orientation="vertical" ... >
    <LinearLayout android:orientation="horizontal" ... > 
        CONTENTLAYOUTS
    </LinearLayout> 
    ... MORE LINEARLAYOUTS FOR MORE ROWS
</>

その後、これらのアイテムの位置を操作できます。

たとえば、現在の位置を次のように保存できます。

LinearLayout layout1 = (LinearLayout) findViewById(R.id.layout1);
int position1 = layout1.getTop();

LinearLayout layout2 = (LinearLayout) findViewById(r.id.layout2);
int position2 = layout2.getTop();

AnimationSet animSet = new AnimationSet(...);
//define your animations here, or load them from resources
//to move each view to each of the two positions, changing the 
//Y coordinate of the Views

両方のアニメーションを同時に実行するには、必ず AnimationSet を使用してください。

これが役立つことを願っています!わかりにくい点がありましたらお知らせください。解決に努めます。

于 2011-07-27T18:19:35.740 に答える