2016-06-27 15 views
-1

Können Sie mir Tipps geben, wie Sie diese Schaltfläche erstellen und klickbar machen? Diese Schaltfläche sollte aus Bild und Text (oder Beschreibung) bestehen. Vielen Dank. ButtonWie kann dieser Button in AndroidStudio klickbar gemacht werden?

+3

Ich stimme für clos e diese Frage als Off-Thema, weil es nichts gibt, was Sie versucht haben und klare Anforderung –

+0

Sie können klicken Sie auf den Link "Button" und sehen Sie das Bild –

+1

bitte erklären Sie mehr. –

Antwort

0

dieses Bild zu Drawables fügt dann

diesen Code verwenden
<ImageButton 
    android:id="@+id/imageButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:src="@android:drawable/your image name" /> 
0
<LinerarLayout 
    android:id="@+id/btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:weightSum="2" 
    android:orientation="vertical"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:layout_weight="1" 
    android:src="@drawable/your image name" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:margin="10dp" /> 

</LinerarLayout> 
0

in OnCreate- (es), wie diese

public class MainActivity extends Activity { 

ImageView imgClick; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 

imgClick = (ImageView)findViewById(R.id.imageView1); 

imgClick.setOnClickListener(new View.OnClickListener() { 

@Override 
public void onClick(View v) { 

Toast.makeText(MainActivity.this, "You clicked on ImageView", Toast.LENGTH_LONG).show(); 

} 
}); 
} 
} 

in XML Bildmenge ID

<LinerarLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:src="@drawable/yourimage" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="your Text" 
    android:padding="5dp" /> 

</LinerarLayout> 
Verwandte Themen