Android用户界面之常用控件scrollView、RatingView 、ImageSwitcher、gallery、editText 2018/8/13

scrollView

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <QuickContactBadge
            android:id="@+id/quickContactBadge2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">


            <RadioButton
                android:id="@+id/radioButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="RadioButton" />

            <RadioButton
                android:id="@+id/radioButton4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="RadioButton" />

            <RadioButton
                android:id="@+id/radioButton5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="RadioButton" />

        </RadioGroup>
    </LinearLayout>
</ScrollView>

RatingView

        ratingBar = findViewById(R.id.ratingBar);
        ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
                Toast.makeText(AtyUsingRatingBar.this,"评价为:"+v , Toast.LENGTH_SHORT).show();
            }
        });

ImageSwitcher

    private ImageSwitcher switcher;
    private boolean showImg1 = true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_using_imageswitcher);

        switcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);

        switcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new ImageView(AtyUsingImageSwitcher.this);
            }
        });

        switcher.setInAnimation(AnimationUtils.loadAnimation(AtyUsingImageSwitcher.this, android.R.anim.fade_in));
        switcher.setOutAnimation(AnimationUtils.loadAnimation(AtyUsingImageSwitcher.this, android.R.anim.fade_out));

        switcher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showImg1 = !showImg1;

                showCurrentImage();
            }
        });

        showCurrentImage();
    }


    private void showCurrentImage() {
        if (showImg1) {
            switcher.setImageResource(R.drawable.img1);
        } else {
            switcher.setImageResource(R.drawable.img2);
        }
    }
<Gallery
    android:id="@+id/gallery"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"></Gallery>


    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
    for (int i= 0 ; i<20 ;i++){
        adapter.add("Item"+i);
    }

    gallery = findViewById(R.id.gallery);
    gallery.setAdapter(adapter);

editText

      editText = findViewById(R.id.editText);

        btnGetText = findViewById(R.id.btnGetText);

        btnGetText.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(editText.getText())) {
                    Toast.makeText(AtyUsingEditText.this, "文本为空", Toast.LENGTH_SHORT).show();

                } else {
                    Toast.makeText(AtyUsingEditText.this, editText.getText().toString(), Toast.LENGTH_SHORT).show();

                }
            }
        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值