[英]Android studio Relative Layout click and go to another form - java
I have a relative layout with an image and 2 texts.我有一个图像和 2 个文本的相对布局。 I need when the user presses the relative layout to go to another activity and show those texts and image in a bigger format.我需要当用户按下相对布局转到另一个活动并以更大的格式显示这些文本和图像时。 Is this possible?这可能吗? If yes how i do this?如果是,我该怎么做? This is what i have done: https://i.stack.imgur.com/piUjZ.png这就是我所做的: https : //i.stack.imgur.com/piUjZ.png
Yes, its possible.是的,这是可能的。
Just add OnClickListener to your relative layout, and pass Intent to next activity.只需将OnClickListener添加到您的相对布局,并将 Intent 传递给下一个活动。
1 - Give your RelativeLayout an ID 1 - 给你的 RelativeLayout 一个 ID
2 - Set your RelativeLayout
XML to android:clickable="true"
2 - 将您的RelativeLayout
XML 设置为android:clickable="true"
Your final xml will be look like this:您的最终 xml 将如下所示:
<RelativeLayout
android:id="@+id/RelativeLayoutTest"
android:clickable="true">
3 - Then add the code in your onCreate method : 3 - 然后在您的 onCreate 方法中添加代码:
RelativeLayout relative1 = (RelativeLayout) findViewById(R.id.RelativeLayoutTest);
relative1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//you can pass image & text over here using putExtra()
startActivity(new Intent(this, YOURCLASS.class) );
}
});
Yes, you can do it.是的,你可以做到。 Take bigger TextView and ImageView and set visibility gone by default.使用更大的 TextView 和 ImageView 并默认设置可见性。 Set onClickListener on Relative Layout by findViewById and onClick of RelativeLayout turn visibility on of both views and make gone visibility of smaller views.通过 findViewById 在相对布局上设置 onClickListener 和 RelativeLayout 的 onClick 打开两个视图的可见性并使较小视图的可见性消失。
set relativelayout click listener and pass all these three using设置relativelayout click listener并使用这三个传递
intent.putExtra("name",name[postion]);
intent.putExtra("name",image[postion]);
intent.putExtra("name",text[postion]);
and get these into your second activity and show where you want to show并将这些纳入您的第二项活动并展示您想要展示的位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.