簡體   English   中英

如何在linearlayout中設置帶有圖像的textview

[英]how to set textview with image in linearlayout

我想像這樣的圖片創建屏幕http://imgur.com/UVKCZdu我的屏幕網址看起來像這個http://imgur.com/gLQw4iV我的屏幕無法調整facebook twitter iccon還在3個按鈕下方的底部顯示空間修復它們? 幫我下面是我的xml代碼

            <?xml version="1.0" encoding="UTF-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#C0C0C0" >

        <ImageView
            android:id="@+id/test_button_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:paddingTop="5dp"
            android:src="@drawable/icon" >
        </ImageView>

        <TextView
            android:id="@+id/test_button_text2"
            android:layout_width="wrap_content"
            android:paddingTop="10dp"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/test_button_image"
            android:paddingLeft="10dp"
            android:layout_toRightOf="@+id/test_button_image"
            android:text="San Diego Unified"
            android:textColor="#000000"
            android:textSize="20sp" >
        </TextView>

        <TextView
            android:id="@+id/test_button_text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
              android:paddingLeft="10dp"
            android:layout_alignLeft="@+id/test_button_text2"
            android:layout_below="@+id/test_button_text2"
            android:paddingBottom="10dp"
            android:text="SCHOOL DISTRICT"
            android:textColor="#000000" >
        </TextView>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        a
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:layout_weight="1"
            android:ellipsize="end"
            android:gravity="left|center_vertical"
            android:singleLine="true"
            android:text="HEALTHY BODIES HEALTHY MINDS "
            android:textColor="#000000"
            android:textSize="12sp" />

        <ImageButton
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:src="@drawable/facebook" />

        <ImageButton
            android:id="@+id/button"
            android:layout_width="wrap_content"
             android:layout_height="40dp"
            android:src="@drawable/twitter"
            android:text="Button Text" />
    </LinearLayout>
    <RelativeLayout
        android:layout_marginTop="10dp"

 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >

 <EditText
    android:id="@+id/editText1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Search School By Name"
    android:layout_centerVertical="true" >

 </EditText>
 <ImageView
    android:id="@+id/imageView1"
    android:padding="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/editText1"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignRight="@+id/editText1"
    android:src="@drawable/title_search" />

</RelativeLayout>

     <TextView
            android:id="@+id/txtCaption"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
         android:background="#ffffff"
            android:paddingBottom="3dp"
            android:paddingLeft="10dp"
            android:paddingTop="3dp"
            android:text="SELECT A SCHOOL TO VIEW LUNCH OR BREAKFAST MENUS"
            android:textColor="#000000"
            android:textSize="10sp"
            android:textStyle="bold" />
     <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#000000" />

    <LinearLayout
        android:id="@+id/lytContent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/txtCopyright"

        android:background="#ffffff"
        android:layout_below="@+id/lytTitlebar"
        android:orientation="vertical" >



        <ListView
            android:id="@+id/listMainMenu"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="@color/background"
            android:dividerHeight="1dip"
            android:fadeScrollbars="true" />
    </LinearLayout>
     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"

        android:background="#a8a8a8"
        >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#a8a8a8"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.333"
            android:background="@drawable/button_style"
            android:text="FARM TO SCHOOL"
            android:textColor="@color/text"
            android:textSize="8sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.333"
            android:background="@drawable/button_style"
            android:text="TAKE A SURVEY"
            android:textColor="@color/text"
            android:textSize="8sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.333"
            android:background="@drawable/button_style"
            android:text="SHARE THIS APP"
            android:textColor="@color/text"
            android:textSize="8sp"
            android:textStyle="bold" />
    </LinearLayout>
    </LinearLayout>
  </LinearLayout>

你不能setText在ImageView的..這只是為了TextViews

您可以做的是將ImageView和TextView包裹在FrameLayout中,然后在TextView上執行setText 確保先定義ImageView,使其位於TextView的z順序下方。

像這樣將圖像添加到文本視圖:

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:drawableRight="@drawable/protection_unprotected"
            android:gravity="center_vertical"
            android:paddingRight="5dp"
            android:text="@string/protection_unprotected"
            android:textSize="18sp"
            android:textStyle="bold" />

android:drawableRight =“ @ drawable / protection_unprotected”

對於您的Facebook和Twitter按鈕,您可以添加

android:background = "@null"

ImageButton標記中,以獲得按鈕中不需要的背景。

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#a8a8a8"
        android:orientation="horizontal" >

<RelativeLayout
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:id="@+id/headerLinearLay"
    android:orientation="horizontal">
    <ImageView
        android:id="@+id/avatarImageView"
        android:src="@drawable/icon"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"></ImageView>
    <TextView
        android:id="@+id/usernameTextView"
        android:text="TextView"
        android:paddingLeft="4dp"
        android:layout_toRightOf="@id/avatarImageView"
        android:layout_centerVertical="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"></TextView>
</RelativeLayout>
</LinearLayout>

暫無
暫無

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

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