简体   繁体   中英

how to set textview with image in linearlayout

i wan tto create sccreen like this image http://imgur.com/UVKCZdu my screen url is looklike this http://imgur.com/gLQw4iV my screen not adjust facebook twitter iccon also show space on bottom below 3 buttons how do i fixed them? help me below is my xml code

            <?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>

You can't setText in an ImageView.. that's just for TextViews

What you can do instead is wrap an ImageView and a TextView inside a FrameLayout, then do your setText on the TextView. Make sure you define the ImageView first, so it's below the TextView's z-order.

Add image to text view like this:

        <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"

For your Facebook and Twitter buttons you can add

android:background = "@null"

inside ImageButton tags for the unwanted background in buttons.

    <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM