我已經徹底研究過這些問題,但還找不到答案。另外,因爲我不是母語的人,所以我對我英語不好的藉口。關於動畫,listview的一部分沒有顯示
問題:在我的android佈局中,我們在status_text下面有一個帶有listview的status_text。當觸摸status_text時,我們爲status_text和listview上的「向下移動」設置動畫,以便只有第一個listview行仍在屏幕上。列表視圖現在仍然可用。
當再次觸摸status_text時,我們將status_text和listview向上移動,以便listview使用屏幕的一半。
我們正面臨的問題是,在「向上移動」期間,只有第一行是動畫。 「向上移動」後,其他行突然出現。
我們想要的是'向上移動',以前隱藏的行在屏幕上滑動。
佈局: 我們正在使用此佈局(略簡化以集中於手頭的問題):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_declareren_choose_verzekerden"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Dummy anchor to put top of listview in the middle of the screen -->
<RelativeLayout
android:id="@+id/anchor"
style="@style/anchor_status_container"
android:layout_centerVertical="true" >
</RelativeLayout>
<!-- Example image -->
<ImageView
android:id="@+id/my_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/footer"
android:adjustViewBounds="true"
android:contentDescription="@string/image_description"
android:scaleType="centerCrop"
android:src="@drawable/empty" />
<!-- Clickable text which moves up and down on click -->
<RelativeLayout
android:id="@+id/status_container"
style="@style/status_container"
android:layout_alignTop="@id/anchor"
android:background="@color/white" >
<TextView
android:id="@+id/status_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/spacing_sml"
android:layout_alignTop="@id/status_container" />
</RelativeLayout>
<!-- Listview which moves up and down with the status_container -->
<RelativeLayout
android:id="@+id/listView_container"
style="@style/padding_content_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/status_container"
android:background="@color/white" >
<ListView
android:id="@+id/mylistView"
style="@style/myListviewStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:divider="@null"
android:dividerHeight="0dp" />
</RelativeLayout>
<!-- Footer with buttons -->
<RelativeLayout
android:id="@+id/footer_button_container"
style="@style/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button_again"
style="@style/btn_secondary"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/opnieuw"
android:visibility="gone" />
<Button
android:id="@+id/button_next"
style="@style/btn_primary"
android:layout_width="wrap_content" />
</RelativeLayout>
</RelativeLayout>
和代碼(又有點簡化在手,只顯示問題有些褪色 - 輸入/輸出和旋轉被刪除):
// The code
@Override
public void onClick(View view)
{
int viewId = view.getId();
if (viewId == R.id.status_container)
{
// Someone clicked the text, move the statusbar (and so the listview) up or down
if (this.viewIsInUpperPosition)
{
startStatusAnimation();
}
}
}
private void startStatusAnimation()
{
if (animationIsRunning)
{
return;
}
setAnimationIsRunning(animValues.START);
// 0. Initialisation
final View statusContainer = (View) getView().findViewById(R.id.status_container);
final View listContainer = (View) getView().findViewById(R.id.listView_container);
final ListView listView = (ListView) getView().findViewById(R.id.myListView);
final View footerButtonContainer = (View) getView().findViewById(R.id.footer_button_container);
// 1. Calculate distance for animation
if (toggleViewDistance == 0)
{
int listViewContainerHeight = listContainer.getHeight();
int footerHeight = footerButtonContainer.getHeight();
int spaceForListView = listViewContainerHeight - footerHeight;
toggleViewDistance = spaceForListView;
}
// 2. Decide if the movement is up or down
float translationDistance = (viewIsInUpperPosition) ? toggleViewDistance : 0 - toggleViewDistance;
// 3. Create the animation
TranslateAnimation yMove = new TranslateAnimation(0, 0, 0, translationDistance);
yMove.setDuration(animValues.ANIMATION_Y_DURATION);
yMove.setInterpolator(new AccelerateDecelerateInterpolator());
// Do here something with scaling and rotating of other objects, not relevant for the question on StackOverflow
// 4. Actions after animation
yMove.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationEnd(Animation arg0)
{
// Fade de listView in als je van onderen naar boven animeert
if (!viewIsInUpperPosition)
{
// Do some fading, outside scope of question
}
// Create layout after the animation
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) statusContainer.getLayoutParams();
if (viewIsInUpperPosition)
{
// View was previously in upper position, now put the statusbar aligned with the footer
params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ABOVE, footerButtonContainer.getId());
}
else
{
// View was previously in bottom position, so put it under the anchor
params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_TOP, R.id.anchor);
}
}
statusContainer.setLayoutParams(params); // Set the new layout params
viewIsInUpperPosition = !viewIsInUpperPosition;
setAnimationIsRunning(animValues.END);
}
@Override
public void onAnimationRepeat(Animation arg0)
{
// Empty
}
@Override
public void onAnimationStart(Animation arg0)
{
// empty
}
});
// 5. Start the animation
statusContainer.startAnimation(yMove);
listContainer.startAnimation(yMove);
}
任何關於如何在屏幕上列表視圖的行「滑入」的建議?非常感激!