【问题标题】:Change the view of TabHost + Format buttons like a real keypad || Android像真正的键盘一样更改 TabHost + 格式按钮的视图 ||安卓
【发布时间】:2013-12-04 16:01:02
【问题描述】:

好吧..首先,我是 Eclipse 新手,Android 开发新手,Java..

我必须制作一个 VoIP 应用程序,我设置了一些选项卡(是的,文本搞砸了):

这是我的 XML 代码。

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

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:orientation="horizontal"
                android:id="@+id/Recents"
                android:layout_width="match_parent"
                android:layout_height="match_parent" 
                android:text="Recents">



            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:id="@+id/Keypad"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Keypad" >

                <Button
                    android:id="@+id/bNumber1"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1" />
                <Button
                    android:id="@+id/bNumber2"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2" />
                <Button
                    android:id="@+id/bNumber3"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3" />
                <Button
                    android:id="@+id/bNumber4"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="4" />
                <Button
                    android:id="@+id/bNumber5"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="5" />
                <Button
                    android:id="@+id/bNumber6"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="6" />
                <Button
                    android:id="@+id/bNumber7"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="7" />
                <Button
                    android:id="@+id/bNumber8"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="8" />
                <Button
                    android:id="@+id/bNumber9"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="9" />
                <Button
                    android:id="@+id/bNumber0"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="0" />


                <Button
                    android:id="@+id/bCall"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Call" />

                <Button
                    android:id="@+id/bSMS"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="SMS" />
                 <Button
                    android:id="@+id/bClear"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="C" />

                <TextView
                    android:id="@+id/etNumberField"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:ems="10"
                    >
                </TextView>

            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:id="@+id/Sms"
                android:layout_width="match_parent"
                android:layout_height="match_parent" 
                android:text="SMS">
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:id="@+id/Ratings"
                android:layout_width="match_parent"
                android:layout_height="match_parent" 
                android:text="Ratings">
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:id="@+id/Account"
                android:layout_width="match_parent"
                android:layout_height="match_parent" 
                android:text="Account">
            </LinearLayout>

        </FrameLayout>

         </LinearLayout>

          </TabHost>

        </LinearLayout>

现在,我的问题是我必须定位所有“数字”按钮(1、2、3、4 等)并让它们看起来像一个真正的键盘。

我的问题是,我无法在图形布局上真正“看到”它是如何定位的。

我也无法根据内存对按钮进行编码,因为我还是新手。 有没有人可以帮助我编写代码,将它们格式化为类似键盘的格式?

或者甚至给我一个解决方案,告诉我如何在编码时看到定位?

提前致谢,

帕拉蒙!

【问题讨论】:

  • 如果你想设计一个Android UI,你将不得不做你的功课。阅读有关 TableLayout 的信息——它使生成矩形按钮网格变得“容易”。 developer.android.com/reference/android/widget/TableLayout.html
  • 还有谷歌“android布局教程”。您会发现很多有趣且有用的链接。
  • @DaleWilson Altho 这并不完全符合我的要求,它确实帮助了我。会的!
  • 带有按钮的列的gridview。

标签: java android xml eclipse android-tabhost


【解决方案1】:

好的,经过一番研究,我想通了。

如果有人想知道如何在编码时更改 Tab-View,并能够看到它的样子..-

只需创建一个 .XML 文件,然后按照您希望选项卡的外观对其进行设计。 在此解决方案之前,我必须编辑我的选项卡视图来查看:

稍后,您需要在线性布局中输入&lt;include layout="@layout/recents" /&gt;(“recents”是 .XML 布局名称。)。

我的看起来像这样:

<LinearLayout
    android:id="@+id/Keypad"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:text="Keypad"> 

       <include layout="@layout/keypad" /> 
                               //"keypad" is the name of the .xml file.
</LinearLayout>

这就是你“改变”视图的方式。

另外,由于我是 Android 开发的新手,我想知道如何格式化我的,让它们看起来像一个合法的键盘。

多亏了包含代码,我实际上可以在编码和设计标签时看到它。

截图:

我做了什么:

- 将所有按钮放在一组 3 个中。

所以 1 LinearLayout 将覆盖按钮 1、2 和 3。

另一个将涵盖 4,5 和 6(等等)

- 在 LinearLayouts 上设置权重

这帮助我将它们“推”到了底部。

我知道这可能不是正确或最安全的方法,但只要它有效,我就很满意。

XML 代码:

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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:paddingTop="10dp" >

        <TextView
            android:id="@+id/etNumberField"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:ems="100"
            android:singleLine="true"
            android:textSize="23dp" />

        <Button
            android:id="@+id/bContact"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:padding="10dp"
            android:text="Contact" />
    </LinearLayout>

          <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:padding="1dp">

                    <Button
                        android:id="@+id/bNumber1"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="1"
                        android:padding="10dp" />

                    <Button
                        android:id="@+id/bNumber2"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="2" 
                        android:padding="10dp"/>

                    <Button
                        android:id="@+id/bNumber3"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="3"
                        android:padding="10dp"  />
        </LinearLayout>

         <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:padding="1dp">
                    <Button
                        android:id="@+id/bNumber4"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="4" />
                    <Button
                        android:id="@+id/bNumber5"
                       android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="5" />
                    <Button
                        android:id="@+id/bNumber6"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="6" />
        </LinearLayout>

        <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:padding="1dp">

                    <Button
                        android:id="@+id/bNumber7"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="7" />
                    <Button
                        android:id="@+id/bNumber8"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="8" />
                    <Button
                        android:id="@+id/bNumber9"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="9" />
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:padding="1dp">
                    <Button
                        android:id="@+id/bNumberStar"

                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="*" />
                    <Button
                        android:id="@+id/bNumber0"

                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="0" />
                    <Button
                        android:id="@+id/bNumberHash"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="#" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"

                android:padding="1dp">

    <Button
                        android:id="@+id/bSMS"

                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="SMS" />
                    <Button
                        android:id="@+id/bCall"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="Call"
                        android:textColor="#00FF00"               
                    />



                    <Button
                        android:id="@+id/bClear"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="C"
                         />
                    </LinearLayout>


</LinearLayout>

如果您对此解决方案有任何疑问,或者我可以如何帮助您,请随时在下方发表评论!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 2011-01-18
    • 1970-01-01
    • 2023-03-10
    • 2018-04-19
    • 2014-04-29
    • 1970-01-01
    相关资源
    最近更新 更多