拼图布局发展的Andr​​oid拼图、布局、oid、Andr

2023-09-07 04:45:27 作者:探索欲望

我在Android的一个新手。

I am a newbie in Android.

我想开发一个应用程序,我可以根据按键选择改变屏幕。应用程序可能endup与20 +屏幕,按钮或输入表单。从1画面我到了屏幕切换到其他的画面。我想到的FrameLayout的,我可以改变孩子。

I want to develop an application where I can change the screens based on button selected. Application might endup with 20+ screens with buttons or entry form. From 1 screen I got to change the screen to some other screen. I thought of FrameLayout where I can change the children.

我没有得到的方式来启动。就像我创建了一个活动。我的每一个画面超过其类,所以我可以将它添加到布局?我如何在启动时我的第一个屏幕上。

I am not getting a way to start up. Like I created an Activity. My each screen should exceed which class so I can add it to the Layout ? How do I make my first screen visible on start up.

这些都似乎是简单和无聊的问题,但我真的不能得到的出发点是一样的。任何帮助是AP preciative帮我实现我的目标。

These all seem to be simple and silly questions, but really I can't get a starting point for the same. Any help is appreciative to help me achieve my goal.

更新:

@Ghost,从相比发生在我的脑海解决方案1更的问题。对于屏幕,我只需要显示按钮特定的格式,我添加了一个GridView和与这个网站。

@Ghost, from your solution 1 more question arised in my mind. For screens where I only have to show buttons in specific format, I added a GridView and a ButtonAdapter with the help of this site.

如果我在ButtonAdapter添加clickListener而已,那我怎么才能将参数传递给setIntent(FooFooActivity.this ....)...我有Conext在ButtonAdapter - 我可以将它强制转换为FooFooActivity,并可以在工作。我可以给IFS在ButtonAdapter中的onclick(),以牛逼去正确的画面。但setIntent CNA工作,我说了这样或类似的东西。如果它可以工作,那么多的屏幕我的单GridView和单ButtonAdapter类可以完成所有的工作。

If I add clickListener in ButtonAdapter only, then how can I pass parameters to setIntent(FooFooActivity.this....) ????? I have the Conext in ButtonAdapter - I can typecast it to FooFooActivity and can that work on. I can give ifs in ButtonAdapter in onclick() to make t go to proper screen. But the setIntent cna work the way I am saying or something like that. If it can work, then for many screens my single GridView and single ButtonAdapter class can do all the work.

在试验新UPDATIONS:

@Ghost,我试过,发现ButtonAdapter上述setIntent(FooFooActivity.this ....)亘古不变的工作 - 在ButtonAdapter它不会找到范围FooFooActivity.this。

@Ghost, I tried and found that the above setIntent(FooFooActivity.this....) in ButtonAdapter doesnot work - as in ButtonAdapter it wont find scope for FooFooActivity.this.

在我FooFooActivity,我无法设置onclikcListeners通过ButtonAdapter添加按钮。我试过了 与gridview.getChild(i)中,但只是不以任何方式设置。 在我还做了另外的LinearLayout XML(buttonspage.xml)有6个按钮和一个使用它的DataActivity。这完美的作品,并在按一下按钮也显示FooFooActivity。

要使用多种活动同buttonspage.xml布局,我设置FooFooActivity作为buttonspage的内容,并将其按一下按钮听众。对于1键我设置退出应用程序和其他按钮显示DataActivity。 In my FooFooActivity, I can't set onclikcListeners for buttons added via ButtonAdapter. I tried with gridview.getChild(i), but just doesn't set in any way. I also made another linearlayout xml (buttonspage.xml) with 6 buttons and a DataActivity that uses it. That works perfectly and on button click also shows FooFooActivity.

To use the same buttonspage.xml layout in multiple activities, I set the content of FooFooActivity as buttonspage and set its button click listeners. For 1 button I set to exit the application and for other button to show DataActivity.

所以,这个我有2活动,foofoo把显示DataActivity /退出键和放大器; DataActivity返回到foofoo把。它的启动与放一个周期;结束与FoofooActivity。如果我点击退出首先,它退出。但是如果我点击退出显示DataActivity后,那么它只是不会退出,只显示DataActivity。难道我不能在多个活动中使用相同的布局?或者可能我是想错了地方(我怀疑的话)?同样buttonpage布局我得到了10-12页使用除非按钮和事件不同的文本。所以想对于的一次写入多次使用的。也得到了动态改变这些页面的按钮按钮样式。

So with this I got 2 activity, FooFoo that shows DataActivity/Exit & DataActivity that returns to FooFoo. Its a cycle that starts & ends up with FoofooActivity. If I click "Exit" at first, it quits. But If I click "Exit" after showing DataActivity, then it just doesn't quit and shows DataActivity only. Is it that I can't use same layout in multiple activity ?? Or may I be going wrong somewhere (I doubt so) ? Same buttonpage layout I got to use in 10-12 pages except with different text on button and events. So was thinking for Write Once Use Multiple Times. Also got to change button styles dynamically of all these pages buttons.

感谢

推荐答案

至于你的第一个屏幕上来讲,这取决于该活动,还是直接在运行项目。例如,如果你有你的项目命名为 foofoo把,然后在编译/构建Android项目,机器人本身的名字的第一个类的 FooFooActivity (即,如果你允许机器人创建活动出来的)。当然,您可以重命名的它,然后有自身。所以,一旦你编译你的用户界面在默认的的main.xml 文件,并回到你的java文件 FooFooActivity ,有在的onCreate 方法内的特定行。这条线是的setContentView(R.layout.main); 此行的内容的设置的查看 $ P $里面那个的main.xml 文件psent。当你运行的程序,仿真器启动时,仿真器presents你的的main.xml 如果您的项目不包含任何的编译或运行时错误。

As far as your first screen is concerned, it depends on the activity, and it runs directly when you run the project. For example, if you have your project named as FooFoo, then while compiling/building your android project, android itself names the first class as FooFooActivity (i.e., if you've allowed android to create an activity out of it). Of course, you can rename it then and there itself. So, once you compile your UI in the default main.xml file and come back to your java file FooFooActivity, there's a particular line inside the onCreate method. That line is setContentView(R.layout.main);This line sets the view of the contents present inside that main.xml file. When you run the program, and when emulator starts, the emulator presents the view of your main.xml if your project doesn't contain any compilation or runtime errors.

如今,来到你的20+布局:您可以把它们都在你的布局文件夹中。分配在每个屏幕,您可以到一些屏幕说XYZ用于至少一个按钮,让我们假定类名为ABC。让我们假设你的FooFooActivity类带您到这个ABC类。下面的步骤将引导您完成如何做导航的一部分。

Now, coming to your 20+ layouts: You can have them all in your layout folder. Assign atleast one buttonin each screen that takes you to some screen say "XYZ" and let's assume that the class name is "ABC". Let's also assume that your FooFooActivity class takes you to this ABC class. Following steps will take you through how to do the navigation part.

我。在你的FooFooActivity类的的onCreate 方法,你已经拥有了的setContentView 。现在,这条线之后,加上下面几行:

I. Inside the onCreate method of your FooFooActivity class, you already have the setContentView. Now, after that line, add the following lines:

 Button button = (Button)findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View v) 
                {
                    Intent intent = new Intent(FooFooActivity.this, ABC.class);
                    startActivity(intent);  
                }
            });

按Passing一个Intent 可以引导你自己/你的用户需要的屏幕/活动。

By Passing an Intent you can guide yourself/your user to the desired screen/activity.

二。请记住,在你的ABC类,意味着同样的的onCreate 的方法,把你的XYZ布局中的的setContentView 像这样的:的setContentView(R.layout.XYZ);

II. Please keep in mind that in your ABC class, imply the same onCreate method and place your XYZ layout inside the setContentView like this: setContentView(R.layout.XYZ);

三。在您的清单文件,你在

III. In your manifest file, after your

 <activity
            android:label="@string/app_name"
            android:name=".FooFooActivity" >


            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

添加以下内容:

add the following:

<activity 
            android:name=".ABC"
            android:label="@string/app_name"
            >
        </activity>

一旦你有这些步骤完成后,运行程序。

Once you're done with these steps, run your program.

请注意,这只是用于显示2个屏幕,以你的用户。你需要重复的超过20倍。我不知道/看任何其他方式。

Please note that this is just for showing 2 screens to your user. You need to repeat it for 20+ times. I don't know/see any other way.

至于你的布局而言,我建议你坚持的相对布局或Linear布局。通常大多数的正常的布局可以通过以下任一或它们的组合来实现。如果您想了解更多,你总能找到在Android开发者网站或堆栈溢出。总之,有很多是我一直无法在这里解释一下其他的东西,但我打算在适当的时候。你总是可以参考伟大的著作,如你好的Andr​​oid ,的程序的Andr​​oid 和学习的Andr​​oid 。即使 CommonsWare - 马克·墨菲有他的一套书是pretty的流行。您可以随时与其中任何一个开始。

As far as your layouts are concerned, I'd suggest you stick with Relative Layout or a Linear Layout. Generally most of the "normal" layouts can be achieved by either of these or their combination. If you want more, you can always find help on Android Developers' Site or Stack Overflow. Anyway, there are lot of other things that I haven't been able to explain here, but I intend to in due time. You can always refer to great books such as Hello Android, Programming Android, and Learning Android. Even CommonsWare - Mark Murphy has his set of books that are pretty popular. You can always start off with any of them.

希望这有助于。所有最优秀的!

Hope this helps. All the best!

修改按照你UPDATION:

当然,它会返回最后一项活动,因为我presume你已经下面这段code用你的退出按钮:

Of course it will return the last activity because I presume you've the following piece of code with your exit button:

Button exit = (Button)findViewById(R.id.button2);
        exit.setOnClickListener(new OnClickListener() 
        {

            public void onClick(View v) 
            {
                finish();

            }
        });

所以,你在做什么基本上已经结束了特殊的ABC /主要活动。这意味着,Android将带你到previous屏幕/活动。就这样。如果你保持相同的布局,并计划到使用它的不同的活动,一切都将只是会比较混乱。只需2个屏幕/活动,这是截至目前足以迷惑你。想象一下,有20多可能会发生什么。那么,设计最终留给你。这就是我能说的。

So, basically what you're doing is ending that particular ABC/Main Activity. That means, android will take you to the previous screen/activity. That's all. If you keep the same layout and plan it to use it for different activities, everything will simply get confusing. With just 2 screens/activities, it's confusing enough for you as of now. Imagine what might happen with 20+. Well, the design is ultimately left to you. That's all I can say.