我在LinearLayout中有2个按钮,但它们在当前布局中无法点击。我尝试过使用断点/ Toasts进行测试,但他们肯定没有被按下。我确定它很简单。这是XML。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Bjork">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Bjork"
>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="290dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#ffcc66"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginBottom="20dp"
app:expandedTitleMarginEnd="64dp">
<include layout="@layout/profile_header"
android:layout_height="280dp"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
android:background="@color/Bjork">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/tabLayout"
android:background="@color/Bjork"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<View
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Black"
android:alpha="0"
>
</View>
<LinearLayout
android:id="@+id/Dialog"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@color/White"
android:paddingLeft="@dimen/fab_margin"
android:paddingRight="@dimen/fab_margin">
<Button
android:id="@+id/take_photo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Take Photo"
android:background="@color/Transparent"
android:textColor="@color/Black"
android:drawableLeft="@drawable/ic_take_photo_black"
android:drawablePadding="@dimen/fab_margin"
android:padding="0dp"
android:enabled="true"
/>
<Button
android:id="@+id/library"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Library"
android:background="@color/Transparent"
android:textColor="@color/Black"
android:drawableLeft="@drawable/library"
android:drawablePadding="@dimen/fab_margin"
android:padding="0dp"
android:enabled="true"
/>
</LinearLayout>
</RelativeLayout>
这是Java代码:
takePhoto = (Button) findViewById(R.id.take_photo);
takePhoto.setClickable(true);
takePhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dispatchTakePictureIntent();
}
});
Button library = (Button) findViewById(R.id.library);
library.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent, RequestCodes.IMAGE_PICK);
}
});
答案 0 :(得分:1)
检查前面是否有东西,或者将它们带到前面:library.bringToFront();
和takePhoto.bringToFront();
<强>更新强>
takePhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dispatchTakePictureIntent();
}
});