gpt4 book ai didi

android - 在android中使用按钮加载动画

转载 作者:行者123 更新时间:2023-11-29 22:21:11 25 4
gpt4 key购买 nike

我在 android 中有一个 Activity ,我在 SurfaceView 下设置了一个按钮。结果如下所示:

我对它很满意,除了一件事,按钮上的字写错了,必须正确设置。为此,我使用了这样的动画:

takePhoto = (Button) findViewById(R.id.btnPhoto);
takePhoto.setText(t);

RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.myanim);
ranim.setFillAfter(true);
takePhoto.setAnimation(ranim);

res/anim/myanim 看起来像:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="0" />

但是结果有点令人失望,因为整体看起来是这样的:

enter image description here

文字没问题,但尺寸变小了。

我想要的是保持文本正确和初始大小。我该怎么做???它与 xml 文件中按钮的属性无关,因为我在加载动画时没有更改它们……想法?谢谢……

编辑:xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>

<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />

<RelativeLayout android:layout_width="fill_parent"
android:layout_toRightOf="@id/surface_camera"
android:layout_height="fill_parent"
>

<Button android:layout_width="680dip"
android:layout_height="680dip"
android:id="@+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />

</RelativeLayout>

</RelativeLayout>





IMPORTANT:

In the cases described below...my activity is in `LANDSCAPE` mode and the position of the phone is portrait.Another issue is that when I turn my phone in landscape mode(and here I mean the position of the phone, cause the activity is still landscape) the button doesn't go at the bottom of the phone is stays there.No matter how I turn the phone the button is in the same position!!!!

最佳答案

你应该阅读 this

制作如下两个布局文件夹...

enter image description here

在这两个文件夹中,您的布局文件名应该相同。

layout-port 文件夹中,您的布局文件应该如下所示......

android:layout_toRightOf="@id/surface_camera"

替换为...

android:layout_Below="@id/surface_camera"

如下……

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>

<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />

<RelativeLayout android:layout_width="fill_parent"
android:layout_toBelow="@id/surface_camera"
android:layout_height="fill_parent"
>

<Button android:layout_width="680dip"
android:layout_height="680dip"
android:id="@+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />

</RelativeLayout>

</RelativeLayout>

即使这会被视为不好的做法,但您也可以手动处理,试试这个 ..

    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

int orientation = getResources().getConfiguration().orientation;

if(orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main1);

}
else {

setContentView(R.layout.main2);
}
}

此外,如果您这样做,则无需制作两个布局文件夹,但需要在同一文件夹中放置两个布局文件 main1 和 main2

还有一个选择......

list 中...

<activity android:name=".ActivityName" android:configChanges="keyboardHidden|orientation">

+

在你的 Activity 中......

 @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

int orientation = newConfig.orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT) {

setContentView(R.layout.main2);
}
else {

setContentView(R.layout.main);
}
}

关于android - 在android中使用按钮加载动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7148115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com