[英]Show/Hide Layout onTouch in framelayout
I have a full image fragment. 我有完整的图像片段。 There is a RelativeLayout and LinearLayout in framelayout. 在framelayout中有一个RelativeLayout和LinearLayout。 LinearLayout contain viewpager. LinearLayout包含viewpager。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayoutViewpager">
<com.bogdwellers.pinchtozoom.view.ImageViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<RelativeLayout
android:id="@+id/relativelayoutforbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/save_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save" />
</RelativeLayout>
I want When user first open it it should only show image(Viewpager layout) and if user click on it that show other option like - share and save(RelativeLayout). 我想要当用户第一次打开它时,它应该仅显示图像(Viewpager布局),如果用户单击它,则显示其他选项,例如-share and save(RelativeLayout)。 We can find this type of feature in facebook and whatsapp. 我们可以在facebook和whatsapp中找到这种类型的功能。
Try this type code for visiablity .. 尝试使用这种类型的代码以保持良好的风格。
private void share(){
relativeLayout.setVisibility(View.VISIBLE);
linearLayoutViewpager.setVisibility(View.GONE);
}
linearLayoutViewpager=findViewById(R.id.linearLayoutViewpager);
linearLayoutViewpager.setVisibility(View.VISIBLE);
relativeLayout=findViewById(R.id.relativelayoutforbuttons);
relativeLayout.setVisibility(View.GONE);
it only sample code but mange according your needs. 它只是示例代码,但可以根据您的需要进行管理。
final boolean flag=true;
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (flag){
relativeLayout.setVisibility(View.VISIBLE);
flag=false;
}
else{
relativeLayout.setVisibility(View.GONE);
}
}
});
You can simply hide or unhide the relativeLayout's instance using setVisibility.(..) method on linearLayout or imageviewpager click. 您可以在linearLayout或imageviewpager单击时使用setVisibility。(..)方法简单地隐藏或取消隐藏relativeLayout的实例。
layout: 布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayoutViewpager">
<ImageViewPager
android:id="@+id/viewpager"
android:onClick="onPagerClick"
android:layout_width="200dp"
android:layout_height="200dp" />
</LinearLayout>
<RelativeLayout
android:id="@+id/relative_layout"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/save_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onSave"
android:text="Save" />
</RelativeLayout>
</FrameLayout>
Activity: 活动:
public class TestActivity extends AppCompatActivity {
private boolean isButtonShown = false;
ImageViewPager viewPager;
RelativeLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
viewPager = findViewById(R.id.viewpager);
layout = findViewById(R.id.relative_layout);
}
public void onPagerClick(View view) {
if (isButtonShown) {
isButtonShown = false;
layout.setVisibility(View.GONE);
} else {
isButtonShown = true;
layout.setVisibility(View.VISIBLE);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.