TextView和ImageView在LinearLayout中的位置

发布于 2024-12-11 13:12:54 字数 1090 浏览 8 评论 0原文

我如何使 TextView 的位置位于 LinearLayout 的左侧,而 ImageView 的位置位于 LinearLayout 的右侧,

    <LinearLayout
        android:orientation="horizontal"
        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dip"
        android:layout_marginRight="5dip"
        android:layout_marginLeft="5dip"
        >
        <TextView  
            android:id="@+id/formulaTextKite"
            android:text="@string/formulasAreasKite"
            style="@style/stripFormulasTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />  
        <ImageView
            android:id="@+id/picAreaKite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dip"
            android:layout_marginLeft="2dip"
            android:src="@drawable/areakite"
            />
    </LinearLayout>

谢谢 伊齐克

how do i make the position of TextView in the left of LinearLayout and ImageView in the right of LinearLayout

    <LinearLayout
        android:orientation="horizontal"
        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dip"
        android:layout_marginRight="5dip"
        android:layout_marginLeft="5dip"
        >
        <TextView  
            android:id="@+id/formulaTextKite"
            android:text="@string/formulasAreasKite"
            style="@style/stripFormulasTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />  
        <ImageView
            android:id="@+id/picAreaKite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dip"
            android:layout_marginLeft="2dip"
            android:src="@drawable/areakite"
            />
    </LinearLayout>

thanks
Itzik

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

安穩 2024-12-18 13:12:54

最好使用像这样的RelativeLayout,

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dip"
        android:layout_marginRight="5dip"
        android:layout_marginLeft="5dip"
        >
        <TextView  android:layout_alignParentLeft="true"
            android:id="@+id/formulaTextKite"
            android:text="testing"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />  
        <ImageView android:layout_alignParentRight="true"
            android:id="@+id/picAreaKite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dip"
            android:layout_marginLeft="2dip"
            android:src="@drawable/icon"
            />
    </RelativeLayout>

Its better to use RelativeLayout Like this,

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dip"
        android:layout_marginRight="5dip"
        android:layout_marginLeft="5dip"
        >
        <TextView  android:layout_alignParentLeft="true"
            android:id="@+id/formulaTextKite"
            android:text="testing"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />  
        <ImageView android:layout_alignParentRight="true"
            android:id="@+id/picAreaKite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dip"
            android:layout_marginLeft="2dip"
            android:src="@drawable/icon"
            />
    </RelativeLayout>
友欢 2024-12-18 13:12:54

试试这个,

<LinearLayout 
        android:orientation="horizontal" 
        android:layout_gravity="center_horizontal" 
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent" 
        android:weightSum="3"
        > 
        <TextView   
            android:id="@+id/formulaTextKite" 
            android:text="@string/formulasAreasKite" 
            style="@style/stripFormulasTextView" 
            android:layout_width="0dp"
            android:layout_weight="1" 
            android:layout_height="wrap_content" 
            />   
        <LinearLayout
            android:layout_width="0dp"              //to keep anything in bettween
            android:layout_height="wrap_content"    //if dont need then take weightSum =2 not 3
            android:layout_weight="1">                 
        </LinearLayout>

        <ImageView 
            android:id="@+id/picAreaKite" 
            android:layout_width="0dp" 
            android:layout_height="wrap_content" 
            android:layout_weight="1"
            android:src="@drawable/areakite" 
            /> 
    </LinearLayout> 

Try This,

<LinearLayout 
        android:orientation="horizontal" 
        android:layout_gravity="center_horizontal" 
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent" 
        android:weightSum="3"
        > 
        <TextView   
            android:id="@+id/formulaTextKite" 
            android:text="@string/formulasAreasKite" 
            style="@style/stripFormulasTextView" 
            android:layout_width="0dp"
            android:layout_weight="1" 
            android:layout_height="wrap_content" 
            />   
        <LinearLayout
            android:layout_width="0dp"              //to keep anything in bettween
            android:layout_height="wrap_content"    //if dont need then take weightSum =2 not 3
            android:layout_weight="1">                 
        </LinearLayout>

        <ImageView 
            android:id="@+id/picAreaKite" 
            android:layout_width="0dp" 
            android:layout_height="wrap_content" 
            android:layout_weight="1"
            android:src="@drawable/areakite" 
            /> 
    </LinearLayout> 
ぇ气 2024-12-18 13:12:54

您可以将layout_gravity

用于textView,使用layout_gravity =“left”

,对于imageView使用layout_gravity =“right”

,并且还可以将线性布局方向设置为vertical,这样才能正常工作。

HTH。

you could use layout_gravity

for textView use layout_gravity = "left"

and for imageView use layout_gravity = "right"

and also make your linear layout orientation vertical , for this to work.

HTH.

静谧幽蓝 2024-12-18 13:12:54

我使用了以下 xml 安排并且它有效:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_gravity="center_horizontal" 
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" 
    android:weightSum="3"
    > 
 <ImageView 
        android:id="@bbm" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:src="@drawable/bbm" 
        /> 

<TextView  
        android:id="@+id/formulaTextKite"
        android:text="@string/formulasAreasKite"
        style="@style/stripFormulasTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />  



</LinearLayout> 

I used the Following xml arrangement and it worked:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_gravity="center_horizontal" 
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" 
    android:weightSum="3"
    > 
 <ImageView 
        android:id="@bbm" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:src="@drawable/bbm" 
        /> 

<TextView  
        android:id="@+id/formulaTextKite"
        android:text="@string/formulasAreasKite"
        style="@style/stripFormulasTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />  



</LinearLayout> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文