繁体   English   中英

Android布局 - 无法获取要显示的按钮和文本

[英]Android Layout - Can't Get buttons and text to display

我在这里遇到问题,我对Android上的布局不熟悉,我无法按照自己的意愿进行布局。

我希望它看起来如下:

[Button][Button]
Text Filled Here
Text Filled Here
Text Filled Here
Text Filled Here
Text Filled Here

TextView通过我的messagehelper填充,将文本发送到UI

最终,我的代码将遍历从Web服务检索到的对象列表,并将它们全部显示在自己的行上,并可选择按下一个并在地图上查看它。

目前,我只能单独显示两个按钮或文本,或者同一行中的所有三个按钮,而不是第一行上的两个按钮和向下填充的文本!

这是我的代码:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/buttonLayout" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="1">
    <Button
        android:id="@+id/vehicleButton"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:text="Refresh"
        android:onClick="getVehicles" />
    <Button
        android:id="@+id/logoutButton"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:text="Logout"
        android:onClick="logout" />
    </LinearLayout>

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/textLayout" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
    <TextView
        android:id="@+id/textView1"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>

</LinearLayout>

默认情况下, LinearLayout方向是horizontal ,您需要将xml上的第1和第3个LinearLayout方向更改为vertical

使用android:orientation="vertical"

您可以简化布局:

编辑:如果“向下填充”意味着你想要按钮下面的文字:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >


    <Button
        android:id="@+id/vehicleButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_weight="1"
        android:onClick="getVehicles"
        android:text="Refresh" />

    <Button
        android:id="@+id/logoutButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/vehicleButton"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/vehicleButton"
        android:layout_weight="1"
        android:onClick="logout"
        android:text="Logout" />


    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="false"
        android:layout_alignParentTop="false"
        android:layout_below="@id/vehicleButton"
        android:layout_weight="1"
        android:text="Test"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

为了将textview底部放在彼此底部,使用方向为垂直。

而代码就是这个

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/buttonLayout" 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_weight="1">
<Button
    android:id="@+id/vehicleButton"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_weight="1"
    android:text="Refresh"
    android:onClick="getVehicles" />
<Button
    android:id="@+id/logoutButton"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_weight="1"
    android:text="Logout"
    android:onClick="logout" />
</LinearLayout>

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textLayout" 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="vertical"

>
<TextView
    android:id="@+id/textView1"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_weight="1"
    android:textAppearance="?android:attr/textAppearanceMedium" />
 <TextView
    android:id="@+id/textView1"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_weight="1"
    android:textAppearance="?android:attr/textAppearanceMedium" />

 <TextView
    android:id="@+id/textView1"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_weight="1"
    android:textAppearance="?android:attr/textAppearanceMedium" />


<TextView
        android:id="@+id/textView1"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:textAppearance="?android:attr/textAppearanceMedium" />
 <TextView
        android:id="@+id/textView1"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

</LinearLayout>

尝试这个...

<?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="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

    </LinearLayout>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM