像在Apollo音乐播放器中的Android上的按钮上的文字

时间:2012-09-11 18:27:10

标签: android button android-image android-button

开发时,我是Android平台的新手。但是我会从基本视图中走得更远,我想创建类似以下按钮的东西:

Artists view in the Apollo Music Player

这就是我想要实现的目标。我首先想到一个具有自定义背景的按钮就足够了。但是我不知道如何用里面的文字制作那条较小的深色线条。所有图像都像按钮一样反应,并在您触摸时突出显示。

你能帮助我吗?

3 个答案:

答案 0 :(得分:3)

如果查看source code for Apollo,您可以看到ArtistsFragment不是由Button组成的,而是由an inflated RelativeLayout a subclass创建的SimpleCursorAdapter OnClickListener 3}} class。

由于任何视图都可以有一个{{3}},你可以根据需要创建一个布局,但仍然可以像按钮一样:

// Or load it as an item from an existing layout.
View myView = this.getLayoutInflater().inflate(R.layout.anything);
myView.setOnClickListener(new OnClickListener(){

    public void onClick(View arg0) {
        // Do stuff.
    }

});

答案 1 :(得分:0)

带图像的每个片段都可以是布局,背景设置为适当的图像。然后,您只需将按钮放在布局中。

答案 2 :(得分:0)

您必须使用FramelayoutRelativeLayout。例如:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView  
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 

        android:scaleType="center"
        android:src="@drawable/your_drawabele" />

    <TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        android:layout_gravity="center_horizontal|bottom"

        android:padding="12dip"

        android:background="#AA000000"
        android:textColor="#ffffffff"

        android:text="your_text" />

</FrameLayout>