ClipDrawable資源之徐徐展開的風景

1、創建展示的xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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:orientation="vertical"
    tools:context="com.ui.demo.custom.ClipDrawableActivity">
    <ImageView
        android:id="@+id/image1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/my_clip"
        />
</LinearLayout>
2、創建對應的my_clip資源
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/qingxin_1366_768"
    android:clipOrientation="horizontal"
    android:gravity="center">
</clip>
3、創建顯示的Activity
public class ToggleButtonActivity extends Activity
{
    private ToggleButton toggleButton;
    private Switch switcher;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.toggle_button_layout);
        toggleButton = (ToggleButton) findViewById(R.id.toggle);
        switcher = (Switch) findViewById(R.id.switcher);
        final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.test);
        OnCheckedChangeListener listener = new OnCheckedChangeListener()
        {
            @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                if (isChecked)
                {
                    if (linearLayout != null)
                    {
                        //設置垂直佈局
                        linearLayout.setOrientation(1);
                    }
                }
                else
                {
                    if (linearLayout != null)
                    {
                        //設置水平佈局
                        linearLayout.setOrientation(0);
                    }
                }
            }
        };
        toggleButton.setOnCheckedChangeListener(listener);
        switcher.setOnCheckedChangeListener(listener);
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章