English 中文(简体)
如何在对某些活动的文字调查上添加图像
原标题:How to add images on textview on some event

在我和roid的申请中,我有一份名单和一个名单标题。 a. 清单负责人一使用这一规定:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
    android:weightSum="1">

    <TextView android:text="#" android:layout_height="wrap_content"
        android:layout_width="0dp" android:background="@drawable/back"
        android:layout_weight=".05" android:gravity="center_horizontal"
        android:id="@+id/header_num"/>:
    <TextView android:text="Summary" android:layout_height="wrap_content"
        android:layout_width="0dp" android:background="@drawable/back"
        android:layout_weight=".55" android:gravity="center_horizontal"
        android:id="@+id/header_summ" />
</LinearLayout>

for android:background="@drawable/back>:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#ffffff" />
    <stroke android:width="1dip" android:color="#4fa5d5" />


</shape>

现在,根据标题项目,将清单项目分类如下:

ticketnum = (TextView) findViewById(R.id.header_num);
        ticketnum.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Comparator<Ticket> mc;
                mc = new TicketIdComparator();
                Collections.sort(tickets, mc);
                System.out.println(tickets);
                ticket_adapter = new TicketAdapter(getApplicationContext(),
                        R.layout.ticket_details_row, tickets);
                setListAdapter(ticket_adapter);

                ticket_adapter.notifyDataSetChanged();

            }
        });

现在,我只想在座头上看到两幅图像,一个向上和向下arrow,以显示分崩解。

请说明如何添加这两个图像。

感谢。

最佳回答

你可以arrow笑案文左边(这样看一看......) 我认为这是你们想要的吗?

首先在你手提的翻了一番,叫它上Arrow.png,并增加一个叫倒的Arrow。

接着,把arrow弄到案文左边。 观点案文:

myTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.upArrow, 0, 0, 0);

See setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) Use the other arguments to set your arrow above, right, or below the text.

现在,如果你想要改变背景形象(例如放弃R.drawable.back),那么你也将首先拯救Arrow。 页: 1

myTextView.setBackgroundDrawable(R.drawable.upArrow);

See setBackgroundDrawble(Drawable d)

此外,注意到(自2.1起)你可以在你的XML中呼吁你的速记员。 这将使法典更加清洁。 在您的案例中,在座各位中,还有一位在座的听众:

 <TextView 以及roid:text="#" 以及roid:layout_height="wrap_content"
        以及roid:layout_width="0dp" 以及roid:background="@drawable/back"
        以及roid:layout_weight=".05" 以及roid:gravity="center_horizontal"
        以及roid:id="@+id/header_num" 
        以及roid:onClick="myOnclickListener"/>

Then in your Activity class simply add the method:

public void myOnclickListener(View v) {
    ...
}

You could also programmatically add an imageView, though this is more involved. Or you can add in both the imageViews of up 以及 down arrows next to each header, 以及 turn the visibilities on 以及 off for the appropriate once programatically using:

myImageView.setVisibility(View.VISIBLE);

以及

myImageView.setVisibility(View.GONE);

Though I think using bg images or left drawables is the easiest 以及 keeps your xml minimal. If you actually add imageViews, you d probably want to switch to RelativeLayout.

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签