短視訊平臺搭建,Android Studio詳情頁跳轉
阿新 • • 發佈: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="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/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="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/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詳情頁跳轉, 更多內容歡迎關注之後的文章