欲放置2周的TextView向左,和一个按钮向右线性布局内部,这可能吗? 下面是我的代码,我不得不硬编码按钮的LEFTMARGIN,这是不灵活。是否有可能的布局,在不同的方向流动的孩子吗?

<LinearLayout
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="100px"
>
<TextView
android:id="@+id/tc_buttom_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time elapsed"
>
</TextView>
<TextView
android:id="@+id/tc_buttom_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00:00 00"
>
</TextView>
<Button
android:id="@+id/tc2_home"
android:layout_width="70px"
android:layout_height="wrap_content"
android:layout_marginLeft="200px"
android:layout_marginRight="10px"
android:text="Home"
android:layout_weight="0.5"
>
</Button>
</LinearLayout>
有帮助吗?

解决方案

  

欲放置2周的TextView到   左,一个按钮向右   线性布局内,这是   可能的?

不具有单个LinearLayout。你要么需要两个LinearLayouts(一个用于在左边的两个TextViews的列),或一个RelativeLayout的。

  

是否有可能布局的孩子,   在不同的方向流动?

如果由“不同的方向”您的意思是垂直和水平同时,单个LinearLayout只能去在一个方向上。要么使用嵌套LinearLayouts或RelativeLayout

其他提示

要么使用两个线性布局(一个具有水平取向和其他与垂直取向),或者使用相对布局。相对布局比线性和易于使用的强

您需要使用表的布局。看表的布局例子中API的演示。

Table layout - with 'stretch columns' = 1,
 -- Table row  - with width = fill_parent,
    --  Text View,
    --  Text View,
    --  Button,

这将保持你的右按钮推到屏幕的右边缘

的LinearLayout 具有orientation属性。尝试是这样的:

<LinearLayout
    android:id="@+id/widget43"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="100px"
>

使用下列的程序:

 <LinearLayout
            android:id="@+id/widget43"
            android:layout_width="fill_parent"
            android:layout_height="100px"
            android:layout_margin="16dp"
            android:orientation="horizontal">

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

                <TextView
                    android:id="@+id/tc_buttom_text1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Time elapsed"></TextView>

                <TextView
                    android:id="@+id/tc_buttom_text2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="00:00:00 00"></TextView>
            </LinearLayout>

            <Button
                android:id="@+id/tc2_home"
                android:layout_width="70px"
                android:layout_height="wrap_content"
                android:layout_marginLeft="200px"
                android:layout_marginRight="10px"
                android:layout_weight="0.5"
                android:text="Home"></Button>
        </LinearLayout>

有关更多的Android布局教程和实施例: HTTP://www.viralandroid。 COM / 2015/11 /机器人-layouts.html

我使用两个LinearLayouts这样的:

<?xml version="1.0" encoding="utf-8"?>
  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099cc"
    tools:context=".FullscreenActivity">

    <!-- The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc. -->
    <TextView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:text="@string/dummy_content"
        android:textColor="#33b5e5"
        android:textSize="50sp"
        android:textStyle="bold" />

    <!-- This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows. -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/background_dark"
        android:fitsSystemWindows="true">

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="?metaButtonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay"
            android:baselineAligned="false"
            android:orientation="vertical"
            tools:ignore="UselessParent">

            <LinearLayout
                android:id="@+id/fullscreen_choose_controls"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/fullscreen_esop"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="@string/vs_esop"
                    android:textAllCaps="false"
                    android:textColor="@android:color/holo_blue_dark"
                    android:textSize="50sp"
                    android:textStyle="bold" />

                <Button
                    android:id="@+id/dummy_button"
                    style="?metaButtonBarButtonStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="0.3"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:text="@string/dummy_button"
                    android:textColor="@android:color/holo_red_dark"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/fullscreen_android"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="@string/vs_android"
                    android:textAllCaps="false"
                    android:textColor="@android:color/holo_blue_dark"
                    android:textSize="50sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <TextView
                android:id="@+id/fullscreen_make_your_choice"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/vs_make_your_choice"
                android:textColor="@android:color/holo_red_dark"
                android:textSize="50sp"
                android:textStyle="bold" />

        </LinearLayout>
    </FrameLayout>

</FrameLayout>

演示

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top