安卓图书显示界面设计,通过表格显示图书信息,图书信息在逻辑代码中添加。完成相关代码
时间: 2023-06-15 16:05:38 浏览: 68
以下是一个简单的安卓图书显示界面设计,使用表格显示图书信息,并且可以在逻辑代码中添加图书信息:
布局文件 book_display.xml:
```xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<TextView
android:layout_column="1"
android:text="书名"
android:padding="3dip" />
<TextView
android:layout_column="2"
android:text="作者"
android:padding="3dip" />
<TextView
android:layout_column="3"
android:text="出版社"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/book1_title"
android:layout_column="1"
android:text="-"
android:padding="3dip" />
<TextView
android:id="@+id/book1_author"
android:layout_column="2"
android:text="-"
android:padding="3dip" />
<TextView
android:id="@+id/book1_publisher"
android:layout_column="3"
android:text="-"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/book2_title"
android:layout_column="1"
android:text="-"
android:padding="3dip" />
<TextView
android:id="@+id/book2_author"
android:layout_column="2"
android:text="-"
android:padding="3dip" />
<TextView
android:id="@+id/book2_publisher"
android:layout_column="3"
android:text="-"
android:padding="3dip" />
</TableRow>
<!-- 添加更多的书籍信息 -->
</TableLayout>
```
逻辑代码 BookDisplayActivity.java:
```java
public class BookDisplayActivity extends AppCompatActivity {
// 书籍信息
private String[][] books = {
{"计算机网络", "谢希仁", "电子工业出版社"},
{"算法导论", "Thomas H. Cormen", "机械工业出版社"},
{"Java编程思想", "Bruce Eckel", "机械工业出版社"}
// 添加更多的书籍信息
};
private TextView book1_title, book1_author, book1_publisher;
private TextView book2_title, book2_author, book2_publisher;
// 添加更多的书籍信息的 TextView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.book_display);
// 绑定 TextView
book1_title = (TextView) findViewById(R.id.book1_title);
book1_author = (TextView) findViewById(R.id.book1_author);
book1_publisher = (TextView) findViewById(R.id.book1_publisher);
book2_title = (TextView) findViewById(R.id.book2_title);
book2_author = (TextView) findViewById(R.id.book2_author);
book2_publisher = (TextView) findViewById(R.id.book2_publisher);
// 绑定更多的书籍信息的 TextView
// 添加书籍信息到 TextView
book1_title.setText(books[0][0]);
book1_author.setText(books[0][1]);
book1_publisher.setText(books[0][2]);
book2_title.setText(books[1][0]);
book2_author.setText(books[1][1]);
book2_publisher.setText(books[1][2]);
// 添加更多的书籍信息到 TextView
}
}
```
以上代码中,我们使用了表格布局(TableLayout)和表格行(TableRow)来显示书籍信息,每一行使用了三个文本视图(TextView)来显示书名、作者和出版社。在逻辑代码中,我们将书籍信息保存在二维字符串数组 books 中,并且使用 findViewById() 方法来绑定每一个文本视图,最后将书籍信息添加到对应的文本视图中。
相关推荐
![.zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)