0

それぞれが異なるサウンドを再生する 50 個を超える ImageButtons を持つことができる ListView でアクティビティを作成する必要があります。

これが主なアクティビティです (ボタンがあります)。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"

    tools:context="com.werewolve.freaksound.sounds"
    android:background="@drawable/f_background_fit">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:src="@drawable/f_logo" />

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/soundList"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp" />
</RelativeLayout>

これは、リストビューの各行のカスタム レイアウトです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/list_item_string"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:textSize="18sp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/play_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="#00000000"
        android:src="@drawable/f_button_s"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dp" />

</RelativeLayout>

各ボタンは onClick "play_btn" で異なるサウンドを再生し、文字列 "list_item_string" でサウンドに応じたテキストを再生します。

例:


* (笑い声) * (再生ボタン) ***


4

2 に答える 2

0

解決策は、ボタンの名前を表示するための と の両方を持つカスタムListViewオブジェクトを作成することです。次に、カスタム を使用してこれらのオブジェクトを に追加します。の代わりに、単純に通常の画像を使用して. カスタム オブジェクトを表示できるを作成するための優れた例(カスタム の作成方法を含む) は、 http ://www.androidinterview.com/android-custom-listview-with-image-and-text-using- で見つけることができます。アレイアダプター/TextViewImageButtonListViewAdapterImageButtonClickableListViewAdapter

于 2015-01-15T23:24:17.257 に答える