简体   繁体   English

Android studio 相对布局点击并转到另一个表单 - java

[英]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.

相关问题 Android Studio将相对布局替换为带有另一个片段的香气 - Android Studio replace a relative layout insade a framgent with another fragment Java中的findViewByID相对布局(Android) - findViewByID Relative Layout in Java (Android) 单击图像 Slider 和 Go 到 Android Studio 中的另一个活动 - Click Image Slider and Go to Another Activity in Android Studio 在Android Studio中动态列出按钮(相对布局) - Dynamically List Buttons in Android Studio (Relative Layout) 自动组织相对布局中的视图| Android Studio - Automatically organize views in relative layout | Android Studio SearchView: go 到另一个布局,因为在 Android 中按下回车键 - SearchView: go to another layout as enter is pressed in Android Android:通过单击按钮在单个相对布局中创建两个linearlayout - Android: creating two linearlayout in single relative layout with on click button 如何将listview的远程图像花费到另一个布局上,只需单击该项目? …在Android Studio中 - How to spend a remote image of a listview to another layout , to just click on that item ? … In Android Studio Android Studio中相对布局问题中Button上的进度条 - progressbar on top of Button in relative layout issue in Android Studio 上一版Android Studio中缺少相对布局 - Relative Layout missing from the last version of Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM