簡體   English   中英

在頂部設置TextView,在左側屏幕底部設置ImageView

[英]set TextView at the top and ImageView at the bottom of the left screen

<LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="0.0dip"
                    android:layout_marginBottom="1.0dip"
                    android:layout_marginRight="1.0dip"
                    android:layout_weight="1.0"
                    android:background="@drawable/main_buttons_light"
                    android:onClick="btnProfileSettingsClick" >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="top|left"
                        android:gravity="left"
                        android:paddingLeft="8.0dip"
                        android:paddingTop="8.0dip"
                        android:text="@string/activity_main_button_profile_settings"
                        android:textSize="12.0sp"
                        android:color="@color/maintitletext" />

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|left"
                        android:gravity="left"
                        android:paddingBottom="10.0dip"
                        android:paddingLeft="8.0dip"
                        android:src="@drawable/profile_settings" />
                </LinearLayout>

TextViewis位於頂部, ImageView位於底部,但圖像位於正確的位置而不是左側。 我如何一個接一個地設置它並在屏幕的左側站點?

您可以使用RelativeLayout而不是LinearLayout作為textView和imageView的父視圖並設置它們

layout_alignParentLeft
layout_alignParentRight
layout_alignParentTop
layout_alignParentBottom

屬性。

此外,如果您使用RelativeLayout作為父視圖,則可以使用

layout_toLeftOf
layout_toRightOf
layout_above
layout_below

屬性一個接一個地添加子視圖。

編輯:

<RelativeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/containerLayout"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

<TextView 
android:layout_alignParentTop="true" 
android:layout_alignParentLeft="true" 
android:id="@+id/myText"  
android:text="Click Me" />

<ImageView 
android:layout_alignParentBottom="true" 
android:layout_alignParentLeft="true" 
android:id="@+id/myImage" />

</RelativeLayout>

嘗試這個 :

<RelativeLayout  
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" 
    android:layout_alignParentBottom="true"/>

如果您希望保持線性布局 ,只需更改方向即可。 將其添加到LinearLayout xml:

android:orientation="vertical"

要使它在左側對齊,如果它是根布局,只需添加即可

android:gravity="left"

這將使所有兒童左對齊。

否則,如果LinearLayout是另一個布局的子級,則添加:

android:layout_alignParentLeft="true"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM