android - 正确布局android

标签 android android-layout

我正在开发简单的 Android 应用程序。这是我想要创建的布局的模型(只是为了给你一个想法)。 enter image description here

两边会有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>

最佳答案

你会喜欢的

preview

<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 文档不会让你怀孕,所以要多读书。

google design guide for linearLayout and layout_weight

关于android - 正确布局android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20946595/

相关文章:

java - ArrayAdapter 中的内存泄漏

android - APK 文件在直接构建时安装,但在使用分发过程创建 .apk 文件时不安装 (Titanium Studio)

java - 如何将谷歌地图 Android 应用程序导入到另一个 Android 项目中?

android - 如何从测试覆盖范围中排除 Dagger2 类

android - Scrollview 多个 LinearLayouts

android - 模拟器与我的 Activity 布局不匹配

android - 多个 Java fragment 使用的 Asynctask

android - 将 native 操作栏转换为操作栏 Sherlock

Android layout_weight 没有按预期工作

android - ImageView 后的空格