Android graphics status Combination Application (Note), android graphics

Source: Internet
Author: User

Android graphics status Combination Application (Note), android graphics

Purpose: To create a button that has different shapes

In the res drawable-hdpi leleft.pngand the status picture rigth.png.

Drag the image file to the created folder drawable-hdpi.

Create a common XML file and create a graphical state combination step:

Drawable_change → New → Other... → XML File

Note: Change Left_Rigth.XML to left_right.XML.

Enter the following code in Left_Right.XML:

<? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Press status --> <item android: state_pressed = "true" android: drawable = "@ drawable/left"/> <! -- Default status --> <item android: drawable = "@ drawable/riable"/> </selector>

Code in activity_main.XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/container"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.test.MainActivity"    tools:ignore="MergeRootFrame" >        <Button                android:id="@+id/button1"        android:layout_width="30dp"        android:layout_height="wrap_content"        android:background="@drawable/left_right"/>    <Button                android:id="@+id/button2"        android:layout_width="30dp"        android:layout_height="wrap_content"        android:layout_below="@id/button1"        android:background="@drawable/left_right"/> </RelativeLayout>

The test results are as follows:

Reprinted please indicate the source: http://blog.csdn.net/u010499449/article/details/42192383

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.