短視訊平臺搭建,Android Studio詳情頁跳轉

zhibo系統開發發表於2022-05-24

短視訊平臺搭建,Android Studio詳情頁跳轉

關鍵程式碼


MainActivity

public class MainActivity extends AppCompatActivity {
    private Button btnsend;
    private TextView tvcontent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnsend=findViewById(R.id.btnsend);
//        tvcontent=findViewById(R.id.tvcontent);
        btnsend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,SecondActivity.class);
                Bundle bundle=new Bundle();
                bundle.putString("name","海鮮");
                bundle.putInt("age",100);
                bundle.putString("des","來自東海的新鮮海產品");
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
}



SecondActivity

public class SecondActivity extends AppCompatActivity {
    private Button btnback;
    private TextView tvsave;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        btnback=findViewById(R.id.btnback);
        tvsave=findViewById(R.id.tvsave);
        Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        String name=bundle.getString("name");
        int age=bundle.getInt("age",-1);
        String des=bundle.getString("des");
        tvsave.setText("名稱:"+name+"\n\n"+"價格:"+age+"元"+"\n"+"\n"+des);
        btnback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(SecondActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
}


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
    xmlns:app="
    xmlns:tools="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="80dp">
        <ImageView
            android:layout_width="230dp"
            android:layout_height="180dp"
            android:layout_marginTop="10dp"
            android:layout_gravity="center"
            android:id="@+id/iv_image_images"
            android:src="@drawable/food1"></ImageView>
        <Button
            android:id="@+id/btnsend"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:layout_marginTop="50dp"
            android:textFontWeight="12"
            android:textStyle="bold"
            android:text="點選檢視詳情"
            android:textColor="#FFD740"
            android:backgroundTint="#00000000"
            ></Button>
    </FrameLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="80dp">
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center">
    </LinearLayout>
</LinearLayout>


activity_second.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
    xmlns:app="
    xmlns:tools="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".SecondActivity">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="80dp">
        <ImageView
            android:layout_width="300dp"
            android:layout_height="250dp"
            android:src="@drawable/food1"></ImageView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:layout_marginLeft="50dp"
        android:layout_marginTop="10dp">
        <TextView
            android:id="@+id/tvsave"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="tvsave" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center">
        <Button
            android:id="@+id/btnback"
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:layout_marginTop="100dp"
            android:text="返回"
            android:textColor="@color/black"
            android:backgroundTint="#00000000"
            ></Button>
    </LinearLayout>
</LinearLayout>


以上就是短視訊平臺搭建,Android Studio詳情頁跳轉, 更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2896703/,如需轉載,請註明出處,否則將追究法律責任。

相關文章