我正在开发简单的 Android 应用程序。这是我想要创建的布局的模型(只是为了给你一个想法)。
两边会有4张带文字的图片。 最好的方法是什么?这是我到目前为止所拥有的。这样可以吗?还有更好的方法吗?
<LinearLayout 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="#B36E106F"
android:orientation="horizontal"
android:baselineAligned="false"
tools:context=".AddRoute" >
<RelativeLayout
android:id="@+id/add_left_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_margin="5dp"
android:background="#0098FF" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@+id/imageView1"
android:text="From" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_marginTop="48dp"
android:layout_toLeftOf="@+id/textView1"
android:src="@drawable/abc" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView2"
android:layout_marginTop="54dp"
android:src="@drawable/abc" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView3"
android:layout_marginTop="47dp"
android:src="@drawable/abc" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/add_right_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_margin="5dp"
android:background="#0098FF" >
</RelativeLayout>
</LinearLayout>
最佳答案
你会喜欢的
<LinearLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/left"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:background="@drawable/abc_menu_dropdown_panel_holo_light">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/right"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:background="@drawable/abc_spinner_ab_focused_holo_dark">
</LinearLayout>
</LinearLayout>
我正在使用 layout_weight 技巧使左 linearLayout 和右 linearlayout 的宽度相同。
您需要做的是修改样式、背景、边距和填充。
阅读 google android 文档不会让你怀孕,所以要多读书。
关于android - 正确布局android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20946595/