2012-02-09 35 views
0

好吧,所以我对Android非常不好意思,但开始了解它的窍门。在继续之前,我想问一些关于使用API​​视图,列表和布局创建android GUI的一般反馈。对于运动的缘故,我将使用GUI作为一个例子:练习:视图,布局和按钮来创建android图形用户界面

http://imgur.com/71NmI

比方说,我想按钮(也许是“东西”),以能够与无论是在RelativeLayout的互动。一般来说,创建这样一个GUI的最佳实践是什么,以及您将使用哪些API元素来实现它?

[去除不需要的问题]

任何意见,一般和具体,以及实施例的高度赞赏!

编辑:我浏览了你的指南,@Mark Lapasa,感谢你介绍了基础知识。我建议的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"> 


<ImageView android:id="@+id/header" 
    android:layout_width="match_parent" 
    android:background="@drawable/header" android:layout_height="30dp"> 
</ImageView> 

<RelativeLayout android:id="@+id/leftLayout" 
    android:layout_height="match_parent" 
    android:layout_width="wrap_content" 
    android:layout_alignParentLeft="true" android:layout_below="@id/header"> 

    <Button android:text="Left btn1" 
     android:id="@+id/leftBtn1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp"/> 

    <Button 
     android:text="Left btn2" 
     android:id="@+id/leftBtn2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/leftBtn1"/> 

    <Button 
     android:text="Left btn3" 
     android:id="@+id/leftBtn3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/leftBtn2"/> 

</RelativeLayout> 


<RelativeLayout android:id="@+id/rightLayout" 
    android:layout_height="match_parent" 
    android:layout_width="wrap_content" 
    android:layout_alignParentRight="true" android:layout_below="@id/header"> 

    <Button android:text="Right btn1" 
     android:id="@+id/rightBtn1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" android:layout_marginTop="5dp"/> 

    <Button 
     android:text="Right btn2" 
     android:id="@+id/rightBtn2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/rightBtn1"/> 

    <Button 
     android:text="Right btn3" 
     android:id="@+id/rightBtn3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/rightBtn2"/> 
</RelativeLayout> 

<ImageView android:id="@+id/footer" 
    android:layout_width="match_parent" 
    android:background="@drawable/footer" android:layout_height="20dp" android:layout_alignParentBottom="true"> 
</ImageView> 

<RelativeLayout android:id="@+id/gameLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@id/footer" 
    android:layout_below="@id/header" 
    android:layout_toLeftOf="@id/rightLayout" 
    android:layout_toRightOf="@id/leftLayout"> 
</RelativeLayout> 

</RelativeLayout> 

这工作正常。但是,这不是最佳实践。我现在总共有四个RelativeLayouts可以使用。是否有一些顺利的解决方案来实现这一点,而不使用不必要的系统资源和权力?另外,如何设置宽度和高度以便它们独立于设备?

+0

很多问题,可能会分解成多个问题将有所帮助。我想大多数人都可以通过对程序进行简单的修改来尝试和验证。 – kosa 2012-02-09 16:13:48

+0

是的,你是对的。我已经仔细研究了一些细节,并提出了一个似乎不是最佳实践的解决方案。对此解决方案的任何意见都表示赞赏 – 2012-02-09 21:07:24

回答

0

我已经使用了一段时间这并且认为实现这种结果的最佳方式是使用fragments

0

看起来你是相对布局的新手。你可能会想尝试它我的视觉教程,因为我有一个很难有足够的时间与文档:

视觉引导至相对布局在Android中

http://knowledge.lapasa.net/?p=334