Android Layout Help:2 textview vertical内联旁边的1个按钮

时间:2016-05-21 10:43:00

标签: android android-layout android-studio layout android-linearlayout

我尝试做这个布局,但直到现在才得到echec: - 2个textview垂直对齐共享50%宽度,带1个按钮。 - 所有都必须垂直居中。

这是显示我想要的模型:

Mockup

这是我的实际代码:

module.exports = function (grunt) {

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    watch: {

        options: {
            livereload: true
        },

        js: {
            files: ['.dev/**/*.js'],
            tasks: ['concat', 'uglify', 'watch'],
        },
        scss: {
            files: ['./dev/scss/*.scss'],
            tasks: ['sass', 'concat', 'watch'],
            options: {
                reload: true,
                livereload: false,

            }
        },
        html: {
            files: ['./dev/**/*.html', 'watch'],
            tasks: ['copy', 'watch'],
        },
        grunt: {
            files: ['Gruntfile.js'],
            tasks: ['watch'],
        },
    },

    concat: {
        js: {
            src: ['dev/js/script1.js', 'dev/js/script2.js'],
            dest: 'dev/js/script.js',
        },
        css: {
            src: ['./dev/css/nav.css', './dev/css/anim.css', './dev/css/style.css'],
            dest: './dist/css/style.css',
        },
    },

    uglify: {
        build: {
            src: 'dev/js/script.js',
            dest: 'dist/js/script.min.js'
        }
    },

    sass: {                              // Task
        dev: {                            // Target
            files: {                         // Dictionary of files
                './dev/css/style.css': './dev/scss/style.scss',       // 'destination': 'source'
            },
            tasks: ['copy'],
        }
    },

    copy: {
        main: {
            expand: true,
            cwd: './dev/html',
            src: '*.html',
            dest: './dist/html/'
        },
    },
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-sass');


// Default task(s).
grunt.registerTask('default', ['concat', 'uglify', 'sass', 'copy', 'watch']);

};

感谢您的帮助:)

2 个答案:

答案 0 :(得分:0)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">


<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="center_vertical"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TextView
            android:id="@+id/txtOne"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView One" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TextView
            android:id="@+id/txtTwo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView Two" />

    </LinearLayout>

</LinearLayout>

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="vertical">

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

</LinearLayout>

答案 1 :(得分:0)

  

删除嵌套Linear Layouts,这对性能不利。我在Layout中做了一些更改。在AppCompatButton Layout内设Relative Layout并将其宽度设为android:layout_width="wrap_content",并在Linear Layout内删除第一Root Layout

请参阅此内容。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/image_area"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/btn_go"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/PanelName"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:text="Parking Name"
            android:textColor="#000"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/PanelAddress"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:text="Parking Address blablabla Paris Parking Address blablabla Paris Parking Address blablabla Paris"
            android:textColor="#000"
            android:textSize="14sp" />

    </LinearLayout>


    <android.support.v7.widget.AppCompatButton
        android:id="@+id/btn_go"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="24dp"
        android:layout_marginRight="24dp"
        android:layout_marginTop="30dp"
        android:layout_weight="2"
        android:background="#000"
        android:padding="12dp"
        android:text="GO !"
        android:textColor="#FFF" />

</RelativeLayout>

这是屏幕。

enter image description here