如何设置的ImageView和TextView的一个的LinearLayout里面一行 [英] How to set ImageView and the textView in a single line inside a LinearLayout

查看:159
本文介绍了如何设置的ImageView和TextView的一个的LinearLayout里面一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我挣扎设置一个ImageView的和内部的LinearLayout一行一个TextView。我试着用不同的方式,但我仍然无法找到一个妥善的解决办法。这里是code我用:

I'm struggling to set an imageView and a textView in a single line inside LinearLayout. I tried with different ways but still I couldn't find a proper solution. Here is the code I used:

<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="40dp"
    android:clickable="true"
    android:orientation="vertical"
    android:paddingLeft="40dp"
    tools:context=".MainActivity" >

    <ImageView 
        android:id="@+id/icon_image"
        android:layout_width="30sp"
        android:layout_height="30sp"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:layout_gravity="bottom"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher"/>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawablePadding="5dp"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:textSize="14sp"
        android:textStyle="bold" >
    </TextView>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/black" />

</LinearLayout> 

这是它是如何出现:

This is how it is appear :

我应该做的,使正确的吗?

What should I have to do to make correct this?

推荐答案

它是一个的LinearLayout 里面有垂直定位那么自然一切都堆积垂直。总结他们在一个的LinearLayout 与水平定位

Its inside of a LinearLayout with a vertical orientation so naturally everything is stacked "vertically". Wrap them in a LinearLayout with a horizontal orientation

<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="40dp"
android:clickable="true"
android:orientation="vertical"
android:paddingLeft="40dp"
tools:context=".MainActivity" >
<LinearLayout
    .../>
<ImageView 
    android:id="@+id/icon_image"
    android:layout_width="30sp"
    android:layout_height="30sp"
    android:layout_weight="1"
    android:adjustViewBounds="true"
    android:layout_gravity="bottom"
    android:scaleType="fitXY"
    android:src="@drawable/ic_launcher"/>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawablePadding="5dp"
    android:layout_weight="1"
    android:gravity="center_vertical"
    android:textSize="14sp"
    android:textStyle="bold" >
</TextView>
</LinearLayout>
<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/black" />

</LinearLayout> 

在默认情况下,的LinearLayout 具有水平<$​​ C $ C>定位所以不需要提供该属性的子的LinearLayout 它包装了两个查看秒。

By default, LinearLayout has a horizontal orientation so no need to supply that property in the child LinearLayout which wraps the two Views.

这篇关于如何设置的ImageView和TextView的一个的LinearLayout里面一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆