java如何让TranslateAnimation显示线性布局?
我一直在开发一个单屏幕安卓应用程序,但我很难让我的TranslateImation方法正常工作。我正在寻找视图组从应用程序外滑到设计完成的位置
你们能告诉我我做错了什么吗
Java活动:
public class AboutProcess extends AppCompatActivity {
Button myButton;
View myView;
boolean isUp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_process);
myView = findViewById(R.id.my_view);
myButton = findViewById(R.id.my_button);
//set as invisible
myView.setVisibility(View.INVISIBLE);
isUp = false;
}
public void slideUp(View view) {
view.setVisibility(View.VISIBLE);
TranslateAnimation animate = new TranslateAnimation(
0, // fromXDelta
0, // toXDelta
view.getHeight(), // fromYDelta
0); // toYDelta
animate.setDuration(50);
animate.setFillAfter(true);
view.startAnimation(animate);
}
// slide the view from its current position to below itself
public void slideDown(View view) {
TranslateAnimation animate = new TranslateAnimation(
0, // fromXDelta
0, // toXDelta
0, // fromYDelta
view.getHeight()); // toYDelta
animate.setDuration(50);
animate.setFillAfter(true);
view.startAnimation(animate);
}
public void onSlideViewButtonClick(View view) {
if (isUp) {
slideDown(myView);
myButton.setText("SHOW LINKS");
} else {
slideUp(myView);
myButton.setText("HIDE LINKS");
}
isUp = !isUp;
}
}
这里是按钮点击的XML和我试图在屏幕上设置动画的视图组。线性布局中有一组四幅图像
<Button
安卓:id="@+id/my_button"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:fontFamily="@font/lasvegas"
安卓:text="SHOW LINKS"
安卓:backgroundTint="@color/colorPrimaryDark"
安卓:textSize="@dimen/med_font"
安卓:textColor="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toLeftOf="parent"/>
<LinearLayout
安卓:id="@+id/my_view"
安卓:layout_width="match_parent"
安卓:layout_height="125dp"
安卓:layout_marginBottom="@dimen/padding50"
安卓:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
<ImageButton
安卓:contentDescription="@string/desc"
安卓:id="@+id/fb"
安卓:onClick="buttonFB"
安卓:src="@drawable/white_fb"
安卓:background="@null"
安卓:scaleType="centerInside"
安卓:layout_height="match_parent"
安卓:layout_width="0dp"
安卓:padding="@dimen/padding15"
安卓:layout_weight="1" />
<ImageButton
安卓:contentDescription="@string/desc"
安卓:id="@+id/youtube"
安卓:onClick="buttonTube"
安卓:src="@drawable/white_tube"
安卓:background="@null"
安卓:scaleType="centerInside"
安卓:layout_height="match_parent"
安卓:layout_width="0dp"
安卓:padding="@dimen/padding15"
安卓:layout_weight="1" />
<ImageButton
安卓:contentDescription="@string/desc"
安卓:id="@+id/tweet"
安卓:onClick="buttonTweet"
安卓:src="@drawable/white_tweet"
安卓:background="@null"
安卓:scaleType="centerInside"
安卓:layout_height="match_parent"
安卓:layout_width="0dp"
安卓:padding="@dimen/padding15"
安卓:layout_weight="1" />
<ImageButton
安卓:contentDescription="@string/desc"
安卓:id="@+id/www"
安卓:onClick="buttonWWW"
安卓:src="@drawable/white_www"
安卓:background="@null"
安卓:scaleType="centerInside"
安卓:layout_height="match_parent"
安卓:layout_width="0dp"
安卓:padding="@dimen/padding15"
安卓:layout_weight="1" />
</LinearLayout>
当我在我的设备上实现此代码时,按钮会显示并“可单击”,但视图组不在我的屏幕上,我在任何时候都找不到它。有没有关于我遗漏了什么(或者如何为这个概念编写不同的动画)的想法
共 (0) 个答案