android:我可以为 viewflipper 的不同子级使用不同的类吗

发布于 2024-09-28 17:07:21 字数 1472 浏览 3 评论 0原文

我有不同的屏幕可以在 Android 应用程序中工作。 我为此使用 ViewFlipper。 我决定对不同的视图子级使用不同的类

public main extends Activity{
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_in);
    ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);

HomeScreen s = new HomeScreen(getApplicationContext(), getCurrentFocus(), viewFlipper);
  }
} 

,主屏幕类是:-

public class HomeScreen {
private Button signIn;
private Button createAccount;
private View v;
private Context context;
private ViewFlipper viewflipper;

public HomeScreen(Context context,View v,ViewFlipper viewflipper ) {
 this.v=v;
 this.context = context;
 this.viewflipper = viewflipper;


 signIn = (Button) v.findViewById(R.id.button_sign_in_homeScreen);
 createAccount = (Button)v.findViewById(R.id.button_createAccount_homeScreen);
 signIn.setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {
   viewflipper.setDisplayedChild(1);
  }
 });   
}

但显示运行异常 java.lang.RuntimeException:无法启动活动 ComponentInfo 谁能帮帮我吗
getCurrentFocus() 是获取视图的正确方法吗?


我尝试实现的是

  • 我需要使用不同的类来定义、监听视图翻转器的每个子视图的控件
  • 在上面的示例中,HomeScreen是我的视图翻转器的子屏幕之一
  • 但是行< code>v.findViewById 显示错误我认为 getCurrentFocus() 不是发送视图的正确方式

我不知道我正在以正确的方式移动?当我在定义 viewflpper 的类中定义并监听 viewflipper 的所有子级的所有控件时,该类变得非常大。这让我这么想。。

谢谢。

I have different screen to work in an android application.
I'm using ViewFlipper for this.
I decided to used different class for different view children

public main extends Activity{
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_in);
    ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);

HomeScreen s = new HomeScreen(getApplicationContext(), getCurrentFocus(), viewFlipper);
  }
} 

and this the Homescreen class is :-

public class HomeScreen {
private Button signIn;
private Button createAccount;
private View v;
private Context context;
private ViewFlipper viewflipper;

public HomeScreen(Context context,View v,ViewFlipper viewflipper ) {
 this.v=v;
 this.context = context;
 this.viewflipper = viewflipper;


 signIn = (Button) v.findViewById(R.id.button_sign_in_homeScreen);
 createAccount = (Button)v.findViewById(R.id.button_createAccount_homeScreen);
 signIn.setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {
   viewflipper.setDisplayedChild(1);
  }
 });   
}

but is shows run exception
java.lang.RuntimeException: Unable to start activity ComponentInfo
Can anyone please help me
is getCurrentFocus() is the correct way to get the view?


What i try to implement is

  • I need to use different class for defining, listening the controls of each child of view flipper
  • In the above example HomeScreen is one of my the child screen of view flipper
  • But the line v.findViewById is showing error i think that getCurrentFocus() is not the correct way to sent the view

I don't know weather i'm moving in the correct way? When i define and listen all the controls of all children of viewflipper in the Class where i define that viewflpper, that class become very big. That made me to think so..

Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉黛浅 2024-10-05 17:07:21

您可以使用 Intent 执行动画:

步骤 1:在项目的 res 目录下创建 anim 文件夹。

步骤2:创建一个slideleft.xml文件

步骤3:在该文件中键入以下代码

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromXDelta="100%p" android:toXDelta="0"
        android:duration="400" />
</set>

步骤4:类似地创建slideright.xml

步骤5:使用上面的代码,但更改以下

<translate android:fromXDelta="-100%p" android:toXDelta="0"
            android:duration="400" />

步骤6:

 target.startAnimation(AnimationUtils.loadAnimation(HomeScreen.this, R.anim.slide_left));

执行淡入淡出操作,只需在淡入淡出中添加以下代码即可.xml 文件

<?xml version="1.0" encoding="utf-8"?>

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="0.0" android:toAlpha="1.0"
       android:duration="300" />

也同样用于淡出

<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="1.0" android:toAlpha="0.0"
       android:duration="300" />

U can perfrom animation using Intent to:

Step1: create anim folder under res directory in ur project.

Step2: create an slideleft.xml file

Step3: type the following code in that file

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromXDelta="100%p" android:toXDelta="0"
        android:duration="400" />
</set>

step 4: similarly create slideright.xml

step5: use the above code, but change the following

<translate android:fromXDelta="-100%p" android:toXDelta="0"
            android:duration="400" />

step 6:

 target.startAnimation(AnimationUtils.loadAnimation(HomeScreen.this, R.anim.slide_left));

perfroming fadein operation, just add the following code in fadein.xml file

<?xml version="1.0" encoding="utf-8"?>

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="0.0" android:toAlpha="1.0"
       android:duration="300" />

similarly for fade out too

<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="1.0" android:toAlpha="0.0"
       android:duration="300" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文