作者givemepass (〆)
看板AndroidDev
标题Re: [问题] 该如何做出这个画面
时间Mon Sep 5 16:59:00 2011
※ 引述《hhhhomerun (homerun)》之铭言:
: ┌────────────┐
: │┌───┐ ┌───┐│ 大家好我是一个初学新手,想要设计
: ││Button│ │Button││
: │└───┘ └───┘│ 出这样的一个画面,就是在一个页里,最
: │┌──┐┌──┐┌──┐│
: ││tab1││tab2││tab3││ 顶端是两个Button,然後下面是书签页,
: ││ └───────┐│
: ││ ││ 上网有找到书签页的教学,也把书签页做
: ││ ││
: ││ ││ 出来了,可是button就摆不上去了,做不
: ││ ││
: ││ ││ 出那样的版型
: ││ ││
: ││ ││ 希望能请前辈们指导,衷心感谢!
: ││ ││
: ││ ││
: │└──────────┘│
: └────────────┘
图画的不错
不知道是不是长这样?
http://uploadingit.com/file/lwajzo7l2qyreq9i/Tablayout.PNG
如果是, 参考档案在这XD
http://uploadingit.com/file/6sb8wcx1ymdqiu7d/TestLayout.zip
其实想法很简单 我把要呈现的layout分成两部分
其中一部分是上面的两个button,其中一个靠左 一个靠右
另外一部分是下面的tabwidget
所以是这样的 先用tablelayout把两个button包起来
然後tabwidget用tabhost包起来
然後再用linearlayout把tablelayout跟tabhost包起来
XML如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:stretchColumns="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
android:layout_gravity="left"
></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2"
></Button>
</TableRow>
</TableLayout>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
参考看看
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.221.115.4
※ 编辑: givemepass 来自: 61.221.115.4 (09/05 17:01)
1F:推 sorrel20567:推,想请问一下,tablelayout有没有办法让两个button 09/05 18:00
2F:→ sorrel20567:不要离那麽开,就是贴着正中间的线,一个button靠线左 09/05 18:00
3F:→ sorrel20567:一个button靠线右, 我试了很久都排不出想要的样子 09/05 18:01
4F:→ sorrel20567:用linear的margin又很怕手机解析度不同而跑掉 09/05 18:01
http://uploadingit.com/file/gg75nzowlaz3wc1f/TestLayout.png
这样?
用LinearLayout的 android:layout_weight属性
假设button1 属性为1 button2属性为2 则 button1的大小就是 1/(1+2) 同理
假设你要两个大小一样 则 两个数值都设定相同 就可以了
5F:推 hhhhomerun:谢谢你 後来我发现我的问题了 因为我一直用droiddraw在 09/05 20:12
6F:→ hhhhomerun:做版型 结果droiddraw的tabhost只能当作主架构大框不能 09/05 20:13
7F:→ hhhhomerun:像其他layout那样另外拉进去所以就卡住了.. 後来弄了好 09/05 20:14
8F:→ hhhhomerun:久去XML里面删删弄了半天(真的半天)改改终於有弄出来了 09/05 20:15
9F:→ hhhhomerun:谢谢你! 09/05 20:15
※ 编辑: givemepass 来自: 61.221.115.4 (09/06 08:39)