点击图片拉出更多内容

今天在使用app时遇到一个点击图片下拉内容,先看下图片吧,哈哈虽然很丑

其实很简单,思路就是三个布局,顶部一个中间一个底部一个。

上马吧!

<?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        >
        <ImageView
            android:id="@+id/iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"
            android:layout_centerHorizontal="true"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=" 你的数据"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/iv"
            />
        <ImageView
            android:id="@+id/iv_main"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/iv"
            />
    </RelativeLayout>
    
    <RelativeLayout
        android:id="@+id/rl_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:visibility="gone"
        >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="你要显示的内容
            你要显示的内容
            你要显示的内容
            你要显示的内容
            你要显示的内容
            你要显示的内容
            你要显示的内容
            你要显示的内容"
            />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/ss"
        android:layout_width="match_parent"
        android:layout_margin="20dp"
        android:layout_height="match_parent">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="你的数据"
            />
    </LinearLayout>
</LinearLayout>
只有一个框架布局,在其嵌套的布局内添加内容即可。

在mainactivity中就更加简单了:

package zy.com.jydemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {
    ImageView iv;
    RelativeLayout rl;
    boolean b = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.iv_main);
        rl = (RelativeLayout) findViewById(R.id.rl_main);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (b){//如果为true说内容明布局未显示
                    rl.setVisibility(View.VISIBLE);
                    b = false;
                }else {
                    rl.setVisibility(View.GONE);
                    b = true;
                }
            }
        });
    }
}
这样就完成了,很简单吧,其实用不到其他三方框架了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值