标签:post 工程 err 位置 find popup near 固定 float
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cl_main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ffff"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="50dp"
app:layout_anchor="@id/ll_main"
app:layout_anchorGravity="top|right"
android:background="#ff0000" />
</android.support.design.widget.CoordinatorLayout><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cl_main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btn_snackbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="显示简单提示条"
android:textColor="@color/black"
android:textSize="17sp" />
<Button
android:id="@+id/btn_floating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="隐藏悬浮按钮"
android:textColor="@color/black"
android:textSize="17sp" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_btn"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="20dp"
app:layout_anchor="@id/ll_main"
app:layout_anchorGravity="bottom|right"
android:background="@drawable/float_btn" />
</android.support.design.widget.CoordinatorLayout><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cl_main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btn_bottomsheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="显示底部弹窗"
android:textColor="@color/black"
android:textSize="17sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_bottom"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#ffaaaa"
app:behavior_hideable="true"
app:behavior_peekHeight="50dp"
app:elevation="5dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<TextView
android:id="@+id/tv_popup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="底部弹窗菜单"
android:textColor="#000000"
android:textSize="17sp"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>public class BottomSheetActivity extends AppCompatActivity implements OnClickListener {
private Button btn_bottomsheet;
private BottomSheetBehavior behavior;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottomsheet);
btn_bottomsheet = (Button) findViewById(R.id.btn_bottomsheet);
btn_bottomsheet.setOnClickListener(this);
View ll_bottom = (View) findViewById(R.id.ll_bottom);
behavior = BottomSheetBehavior.from(ll_bottom);
//如果立即setState,会报错java.lang.NullPointerException
mHandler.postDelayed(mState, 50);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_bottomsheet) {
if (behavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
btn_bottomsheet.setText("隐藏底部弹窗");
} else {
behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
btn_bottomsheet.setText("显示底部弹窗");
}
}
}
private Handler mHandler = new Handler();
private Runnable mState = new Runnable() {
@Override
public void run() {
behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
};
}Android开发笔记(一百三十四)协调布局CoordinatorLayout
标签:post 工程 err 位置 find popup near 固定 float
原文地址:http://blog.csdn.net/aqi00/article/details/57927695