Android 如何使用相对布局或线性布局设计此布局?
嗨,我正在创建天气小部件应用程序。我已经完成了编程部分。我不熟悉布局设计。请帮助我如何设计这个布局。提前谢谢。按照下面的方法做 创建根线性布局Android 如何使用相对布局或线性布局设计此布局?,android,android-layout,android-linearlayout,android-relativelayout,Android,Android Layout,Android Linearlayout,Android Relativelayout,嗨,我正在创建天气小部件应用程序。我已经完成了编程部分。我不熟悉布局设计。请帮助我如何设计这个布局。提前谢谢。按照下面的方法做 创建根线性布局 <LinearLayout 1 orienation should be vertical dont close it > <LinearLayout 2 orientation should be horizontal for adding upper row dont close it to > <
<LinearLayout 1
orienation should be vertical dont close it >
<LinearLayout 2
orientation should be horizontal for adding upper row dont close it to >
<LinearLayout 3
orientation should be vertical to add 2 textview
add 2 textview inside it close it />
<LinearLayout 4
orientation again should be vertical to add textview and image view
add textview and imageview to it and close it />
Now close LinearLayout 2 />
<LinearLayout 5
orienation should be horizontal to add 3 textview
add them inside this LinearLayout and close it />
Then close LinearLayout1 your root LinearLayout />
现在关闭LinearLayout 2/>
然后关闭LinearLayout1根LinearLayout/>
按照以下方法进行操作
创建根线性布局
<LinearLayout 1
orienation should be vertical dont close it >
<LinearLayout 2
orientation should be horizontal for adding upper row dont close it to >
<LinearLayout 3
orientation should be vertical to add 2 textview
add 2 textview inside it close it />
<LinearLayout 4
orientation again should be vertical to add textview and image view
add textview and imageview to it and close it />
Now close LinearLayout 2 />
<LinearLayout 5
orienation should be horizontal to add 3 textview
add them inside this LinearLayout and close it />
Then close LinearLayout1 your root LinearLayout />
现在关闭LinearLayout 2/>
然后关闭LinearLayout1根LinearLayout/>
这正是您现在想要的,根据您的需要为所有小部件添加边框……
这正是您现在想要的,根据您的需要为所有小部件添加边框……如下所示:
LL(Ver)
LL(Hor)
LL(Ver)
TV
TV
FL
IV (match_parent for height and width)
TV (wrap_content for both)
LL(Hor)
TV (weight = 1)
TV (weight = 1)
TV (weight = 1)
LH:线性布局
电视:文本视图
FL:框架布局
IV:ImageView如下所示:
LL(Ver)
LL(Hor)
LL(Ver)
TV
TV
FL
IV (match_parent for height and width)
TV (wrap_content for both)
LL(Hor)
TV (weight = 1)
TV (weight = 1)
TV (weight = 1)
LH:线性布局
电视:文本视图
FL:框架布局
IV:ImageView使用下面的代码,它将正常工作
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="New Text" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="New Text" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="vertical">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="New Text" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="New Text" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="New Text" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="New Text" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
使用下面的代码,它会正常工作
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="New Text" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="New Text" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="vertical">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="New Text" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="New Text" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="New Text" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="New Text" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
您可以同时使用LinearLayout和RelativeLayout创建此布局,但根据我的说法,使用LinearLayout..好的,在线性布局中,我必须以水平方式将其分成两部分。第一部分为纵向。我该怎么办?请解释我使用线性布局,然后使用两个嵌套的水平线性布局来实现底部和顶部。你可以使用线性布局和相对布局来创建此布局,但根据我的说法,使用线性布局。好的,在线性布局中,我必须以水平方式分成两部分。第一部分为纵向。我该怎么办?请给我解释一下,在整个过程中使用一个线性布局,然后使用两个嵌套的水平线性布局来实现底部和顶部。谢谢,我会尝试这个并告诉你汉克斯,我会尝试这个并告诉你