Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当应用程序水平显示时,按钮对齐消失_Java_Android_Eclipse_User Interface_Android Relativelayout - Fatal编程技术网

Java 当应用程序水平显示时,按钮对齐消失

Java 当应用程序水平显示时,按钮对齐消失,java,android,eclipse,user-interface,android-relativelayout,Java,Android,Eclipse,User Interface,Android Relativelayout,我开发了一个应用程序,如下图所示,在垂直视图中 这是此应用程序的代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" an

我开发了一个应用程序,如下图所示,在垂直视图中

这是此应用程序的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeScreen" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="*"
        android:weightSum="4" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/fBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/fStr" />

            <Button
                android:id="@+id/rBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/rStr" />

            <Button
                android:id="@+id/sBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/sStr" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/cBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/cStr" />

            <Button
                android:id="@+id/aBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/aStr" />

            <Button
                android:id="@+id/lBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/lStr" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/oBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/oStr" />

            <Button
                android:id="@+id/tBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/tStr" />

            <Button
                android:id="@+id/eBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/eStr" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/dBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/dStr" />

            <Button
                android:id="@+id/hBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/hStr" />

            <Button
                android:id="@+id/aaBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/aStr" />
        </TableRow>
    </TableLayout>

</RelativeLayout>

strings.xml

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

    <string name="fStr">Fffffffff</string>
<string name="rStr">Rrrrrr</string>
<string name="sStr">Ssssss       </string>
<string name="lStr">Lllll</string>
<string name="oStr">Oooooooooooo</string>
<string name="tStr">Ttttt</string>
<string name="eStr">Eeeeee</string>
<string name="dStr">Dddddddddd</string>
<string name="cStr">Cccccccc</string>
<string name="hStr">Hhhh</string>
<string name="aStr">Aaaaaaaaaa aaaa</string>

</resources>

Fffffffff
RRRR
SSSS
微光
呜呜呜呜
Ttttt
Eeeee
Dddddddddd
中交
啊
aaaaaaaaaaaa
此应用程序有2个问题

  • 按钮图像和文本之间的差距太大
  • 当应用程序处于水平视图时,整个对齐方式会混乱,显示如下
  • 正如您所看到的,没有文本


    如何解决此问题?

    在res文件夹下创建一个名为layout land的新文件夹,并将布局(XML文件)放入该文件夹中


    看看这个,试试这个。。将表格行
    width
    指定为
    match\u parent
    height
    指定为
    wrap\u content
    并移除
    weight
    。然后,如果你给某样东西
    重量
    ,你需要给特定的
    高度
    宽度

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".HomeScreen" >
    
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:stretchColumns="*"
            android:weightSum="4" >
    
            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <Button
                    android:id="@+id/fBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="fStr" />
    
                <Button
                    android:id="@+id/rBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="rStr" />
    
                <Button
                    android:id="@+id/sBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="sStr" />
            </TableRow>
    
            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <Button
                    android:id="@+id/cBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="cStr" />
    
                <Button
                    android:id="@+id/aBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="aStr" />
    
                <Button
                    android:id="@+id/lBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="lStr" />
            </TableRow>
    
            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <Button
                    android:id="@+id/oBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="oStr" />
    
                <Button
                    android:id="@+id/tBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="tStr" />
    
                <Button
                    android:id="@+id/eBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="tStr" />
            </TableRow>
    
            <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <Button
                    android:id="@+id/dBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="tStr" />
    
                <Button
                    android:id="@+id/hBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="tStr" />
    
                <Button
                    android:id="@+id/aaBtn"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:drawableTop="@drawable/ic_launcher"
                    android:layout_weight=".3"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="tStr" />
            </TableRow>
        </TableLayout>
    
    </RelativeLayout>
    

    此问题是由于图像的大小造成的。如果拍摄小尺寸图像,则会遇到此问题……如果要放置大尺寸图像,则必须将RelativeLayout更改为ScrolView
    然后TableLayout height应该是wrap_content…..

    为横向模式res/layout land/name.xml设计另一个同名布局。创建一个布局文件夹,其名称类似于layout land mdpi,并定义相同的布局。在横向情况下,高度采用wrapcontent val,宽度采用填充父对象。(如果不起作用,保持原样)并且testfolder名称为“layout land”?在res文件夹中创建新的文件夹名称it layout land。创建文件夹后,将您的abc.xml放入该文件夹,并根据您的要求进行更改。@Artificial_Intelligence是的文件夹名称为layout-land.OK,谢谢您的回复。这意味着,相同设计的2个副本(经过一些修改)将存在,android可以自动检测加载什么?