喜闻乐见也是我最会的布局阶段
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="150dp" android:hint="@string/EditTextname" android:textColorHint="#ff3" android:gravity="center" android:textColor="#ff0033" android:id="@+id/shuru"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button1" style="@style/text" android:onClick="onClick" android:id="@+id/button1"/> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button2" style="@style/text" android:id="@+id/button2"/> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/TextViewname" android:gravity="center" android:id="@+id/show" android:textColor="#ff0033" style="@style/text" android:onClick="onClick"/> </LinearLayout>
string.xml文件的实现
<resources> <string name="app_name">Activity</string> <string name="button1">进入评估</string> <string name="button2">退出</string> <string name="EditTextname">请输入姓名</string> <string name="TextViewname">评估结果</string> <string name="button3">有</string> <string name="button4">没有</string> </resources> styles.xml文件的实现
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="text"> <item name="android:textSize">20sp</item> </style> </resources> 然后再弄一个布局
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textColor="#ff0033" android:id="@+id/show"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button3" style="@style/text" android:onClick="onClick" android:id="@+id/button3"/> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/button4" style="@style/text" android:onClick="onClick" android:id="@+id/button4"/> </LinearLayout> </LinearLayout>
代码实现参考如下
public class { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tiaozhuan); Intent intent = getIntent(); TextView tvshow=(TextView)findViewById(R.id.show); EditText etshuru=(EditText)findViewById(R.id.shuru); String name=intent.getStringExtra("name"); tvshow.setText(name); } public void onClick(View view){ switch (view.getId()){ case R.id.button1: case R.id.button2: enter(); break; } } private void enter() { EditText etshuru=(EditText)findViewById(R.id.shuru); String name =etshuru.getText().toString(); Intent intent=new Intent(this,JiemianActivity.class); intent.putExtra("name",name+"同学:学习Android有没有信心?"); startActivity(intent); }}
public class { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.jiemian2); Intent intent = getIntent(); TextView tvshow=(TextView)findViewById(R.id.show); String name=intent.getStringExtra("name"); tvshow.setText(name); } public void onClick(View view){ switch (view.getId()){ case R.id.button3: ruturn(); break; case R.id.button4: ruturn2(); break; } } private void ruturn() { Intent intent=new Intent(this,TiaozhuanActivity.class); Button btnbutton3=(Button)findViewById(R.id.button3); String name=btnbutton3.getText().toString(); intent.putExtra("name","评估内容返回为:"+name); startActivity(intent); } private void ruturn2() { Intent intent=new Intent(this,TiaozhuanActivity.class); Button btnbutton4=(Button)findViewById(R.id.button4); String name=btnbutton4.getText().toString(); intent.putExtra("name","评估内容返回为:"+name); startActivity(intent); } }
最后的最后
作业的布局是自力更生
然而程序的实现却是一脸懵逼
参考了已有同学的代码
改造之后才有了现在的作业
发现代码的实现还有很大的问题
发现很多东西只是看的熟悉
然而根本不知道具体左右
日后的重点要弱化界面而要尽力弄懂程序的实现
时间: 2024-10-12 23:38:34