首页页面

liuyuchen_part
yuchen 6 months ago
parent cb162566ed
commit 8f4981f481

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,357 @@
package com.startsmake.llrisetabbardemo.activity;
import android.Manifest;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import com.startsmake.llrisetabbardemo.R;
import com.startsmake.llrisetabbardemo.model.Product;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
public class SearchActivity extends AppCompatActivity {
private EditText searchEditText;
private ImageButton backButton;
private ImageButton cameraButton;
private com.google.android.flexbox.FlexboxLayout historyContainer;
private com.google.android.flexbox.FlexboxLayout recommendContainer;
private TextView clearHistoryText;
private TextView expandHistoryText;
private SharedPreferences sharedPreferences;
private static final String SEARCH_HISTORY = "search_history";
private static final int MAX_HISTORY_COUNT = 6; // 最大存储6条
private static final int VISIBLE_HISTORY_COUNT = 4; // 默认显示4条
private boolean isHistoryExpanded = false;
// 相机相关变量
private static final int CAMERA_REQUEST_CODE = 1001;
private static final int CAMERA_PERMISSION_REQUEST_CODE = 1002;
private String currentPhotoPath;
private List<Product> allProducts;
private List<String> recommendKeywords;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
initViews();
initData();
loadSearchHistory();
setupRecommendations();
}
private void initViews() {
searchEditText = findViewById(R.id.search_edit_text);
backButton = findViewById(R.id.back_button);
cameraButton = findViewById(R.id.camera_button);
historyContainer = findViewById(R.id.history_container);
recommendContainer = findViewById(R.id.recommend_container);
clearHistoryText = findViewById(R.id.clear_history_text);
expandHistoryText = findViewById(R.id.expand_history_text);
TextView searchButton = findViewById(R.id.search_button);
// 设置返回按钮
backButton.setOnClickListener((View v) -> finish());
// 设置搜索按钮点击事件
searchButton.setOnClickListener((View v) -> {
performSearch();
});
// 设置搜索页面的相机按钮
cameraButton.setOnClickListener((View v) -> {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
openCamera();
} else {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE);
} else {
openCamera();
}
}
});
// 设置搜索功能
searchEditText.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
});
// 清空历史记录
clearHistoryText.setOnClickListener((View v) -> clearSearchHistory());
// 设置展开/收起按钮
expandHistoryText.setOnClickListener((View v) -> {
isHistoryExpanded = !isHistoryExpanded;
loadSearchHistory();
});
}
private void initData() {
sharedPreferences = getSharedPreferences("search_prefs", MODE_PRIVATE);
// 初始化商品数据
allProducts = new ArrayList<>();
allProducts.add(new Product("1", "Java编程思想", "计算机专业教材", "学习资料", 45.0, ""));
allProducts.add(new Product("2", "高等数学教材", "大学数学课本", "学习资料", 30.0, ""));
allProducts.add(new Product("3", "笔记本电脑", "二手联想笔记本", "数码产品", 1200.0, ""));
allProducts.add(new Product("4", "台灯", "护眼学习台灯", "生活用品", 25.0, ""));
allProducts.add(new Product("5", "Python入门", "编程学习书籍", "学习资料", 35.0, ""));
allProducts.add(new Product("6", "机械键盘", "客制化机械键盘", "数码产品", 150.0, ""));
allProducts.add(new Product("7", "电钢琴", "雅马哈电钢琴", "乐器", 800.0, ""));
allProducts.add(new Product("8", "笔记本", "八成新游戏本", "数码产品", 2000.0, ""));
allProducts.add(new Product("9", "电动车", "二手电动车", "交通工具", 600.0, ""));
allProducts.add(new Product("10", "厚外套", "冬季保暖外套", "服装", 80.0, ""));
// 初始化推荐关键词
recommendKeywords = Arrays.asList(
"Java编程教材", "Python入门书籍", "高等数学课本", "英语四级真题", "考研政治资料", "计算机专业课", "电路分析教程", "机械制图教材", "经济学原理", "心理学导论", "设计素描本", "专业课程笔记","二手笔记本电脑", "机械键盘", "无线鼠标", "蓝牙耳机", "平板电脑", "智能手机", "充电宝", "U盘硬盘", "显示器", "路由器", "相机镜头", "游戏手柄","台灯", "插排", "收纳箱", "穿衣镜",
"瑜伽垫", "体重秤", "电风扇", "暖手宝", "床上桌", "衣柜", "鞋架", "晾衣架","羽毛球拍", "篮球足球", "滑板轮滑", "吉他乐器",
"画笔画具", "围棋象棋", "游泳装备", "健身器材", "登山背包", "帐篷睡袋", "摄影三脚架", "书法字帖"
);
}
private void loadSearchHistory() {
Set<String> historySet = sharedPreferences.getStringSet(SEARCH_HISTORY, new HashSet<>());
List<String> historyList = new ArrayList<>(historySet);
// 按照搜索顺序排序(后搜索的在前)
Collections.reverse(historyList);
historyContainer.removeAllViews();
if (historyList.isEmpty()) {
findViewById(R.id.history_title).setVisibility(View.GONE);
clearHistoryText.setVisibility(View.GONE);
expandHistoryText.setVisibility(View.GONE);
} else {
findViewById(R.id.history_title).setVisibility(View.VISIBLE);
clearHistoryText.setVisibility(View.VISIBLE);
// 计算要显示的历史记录数量
int showCount = historyList.size();
if (!isHistoryExpanded && historyList.size() > VISIBLE_HISTORY_COUNT) {
showCount = VISIBLE_HISTORY_COUNT;
}
// 显示历史记录标签
for (int i = 0; i < showCount; i++) {
String keyword = historyList.get(i);
TextView historyTag = createTagView(keyword, true);
historyContainer.addView(historyTag);
}
// 显示展开/收起按钮
if (historyList.size() > VISIBLE_HISTORY_COUNT) {
expandHistoryText.setVisibility(View.VISIBLE);
if (isHistoryExpanded) {
expandHistoryText.setText("收起");
} else {
expandHistoryText.setText("展开更多(" + (historyList.size() - VISIBLE_HISTORY_COUNT) + ")");
}
} else {
expandHistoryText.setVisibility(View.GONE);
}
}
}
private void saveSearchHistory(String query) {
Set<String> historySet = sharedPreferences.getStringSet(SEARCH_HISTORY, new HashSet<>());
Set<String> newSet = new LinkedHashSet<>(); // 使用LinkedHashSet保持顺序
// 先添加新的搜索(确保在最前面)
newSet.add(query);
// 添加其他历史记录(排除重复项)
for (String item : historySet) {
if (!item.equals(query)) {
newSet.add(item);
}
}
// 如果超过最大数量,移除最旧的
if (newSet.size() > MAX_HISTORY_COUNT) {
List<String> list = new ArrayList<>(newSet);
// 保留最新的6条
List<String> newList = list.subList(0, MAX_HISTORY_COUNT);
newSet = new LinkedHashSet<>(newList);
}
sharedPreferences.edit().putStringSet(SEARCH_HISTORY, newSet).apply();
}
// 相机相关方法保持不变
private void openCamera() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
Toast.makeText(this, "创建文件失败", Toast.LENGTH_SHORT).show();
}
if (photoFile != null) {
currentPhotoPath = photoFile.getAbsolutePath();
Uri photoURI = FileProvider.getUriForFile(this,
getPackageName() + ".fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
}
} else {
Toast.makeText(this, "未找到相机应用", Toast.LENGTH_SHORT).show();
}
}
private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
return File.createTempFile(
imageFileName,
".jpg",
storageDir
);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK) {
if (currentPhotoPath != null) {
Toast.makeText(this, "拍照成功,开始搜索...", Toast.LENGTH_SHORT).show();
searchEditText.setText("图片搜索中...");
performImageSearch();
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
openCamera();
} else {
Toast.makeText(this, "需要相机权限才能拍照搜索", Toast.LENGTH_SHORT).show();
}
}
}
// 图片搜索功能
private void performImageSearch() {
List<Product> similarProducts = findSimilarProducts();
if (similarProducts.isEmpty()) {
searchEditText.setText("未找到相似商品");
Toast.makeText(this, "未找到相似商品", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(this, SearchResultsActivity.class);
intent.putExtra("search_type", "image");
intent.putExtra("search_query", "图片搜索结果");
ArrayList<Product> productList = new ArrayList<>(similarProducts);
intent.putExtra("similar_products", productList);
startActivity(intent);
}
}
private List<Product> findSimilarProducts() {
List<Product> similarProducts = new ArrayList<>();
Collections.shuffle(allProducts);
similarProducts = allProducts.subList(0, Math.min(5, allProducts.size()));
return similarProducts;
}
private void setupRecommendations() {
List<String> randomRecommends = new ArrayList<>(recommendKeywords);
Collections.shuffle(randomRecommends);
List<String> selectedRecommends = randomRecommends.subList(0, Math.min(6, randomRecommends.size()));
recommendContainer.removeAllViews();
for (String keyword : selectedRecommends) {
TextView recommendTag = createTagView(keyword, false);
recommendContainer.addView(recommendTag);
}
}
private TextView createTagView(String keyword, boolean isHistory) {
TextView tagView = new TextView(this);
com.google.android.flexbox.FlexboxLayout.LayoutParams params = new com.google.android.flexbox.FlexboxLayout.LayoutParams(
com.google.android.flexbox.FlexboxLayout.LayoutParams.WRAP_CONTENT,
com.google.android.flexbox.FlexboxLayout.LayoutParams.WRAP_CONTENT
);
params.setMargins(0, 0, 16, 16);
tagView.setLayoutParams(params);
tagView.setPadding(32, 16, 32, 16);
tagView.setText(keyword);
tagView.setTextSize(14);
tagView.setBackgroundResource(R.drawable.tag_background);
tagView.setTextColor(getResources().getColor(android.R.color.darker_gray));
tagView.setOnClickListener(v -> {
searchEditText.setText(keyword);
performSearch();
});
return tagView;
}
private void performSearch() {
String query = searchEditText.getText().toString().trim();
if (!TextUtils.isEmpty(query)) {
saveSearchHistory(query);
Intent intent = new Intent(this, SearchResultsActivity.class);
intent.putExtra("search_query", query);
startActivity(intent);
}
}
private void clearSearchHistory() {
sharedPreferences.edit().remove(SEARCH_HISTORY).apply();
loadSearchHistory();
}
@Override
protected void onResume() {
super.onResume();
loadSearchHistory();
}
}

@ -0,0 +1,115 @@
package com.startsmake.llrisetabbardemo.activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.startsmake.llrisetabbardemo.R;
import com.startsmake.llrisetabbardemo.adapter.SearchAdapter;
import com.startsmake.llrisetabbardemo.model.Product;
import java.util.ArrayList;
import java.util.List;
public class SearchResultsActivity extends AppCompatActivity {
private RecyclerView resultsRecyclerView;
private TextView searchQueryText;
private SearchAdapter searchAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_results);
initViews();
loadSearchResults();
}
private void initViews() {
resultsRecyclerView = findViewById(R.id.results_recycler_view);
searchQueryText = findViewById(R.id.search_query_text);
String query = getIntent().getStringExtra("search_query");
searchQueryText.setText("搜索结果: " + query);
searchAdapter = new SearchAdapter(new ArrayList<>());
resultsRecyclerView.setLayoutManager(new LinearLayoutManager(this));
resultsRecyclerView.setAdapter(searchAdapter);
// 设置返回按钮 - 修复Lambda表达式参数类型
findViewById(R.id.back_button).setOnClickListener((View v) -> {
// 确保数据保存后再返回
finish();
});
}
// 在 loadSearchResults() 方法中添加对图片搜索的支持
private void loadSearchResults() {
String searchType = getIntent().getStringExtra("search_type");
String query = getIntent().getStringExtra("search_query");
if ("image".equals(searchType)) {
// 图片搜索结果
List<Product> similarProducts = (List<Product>) getIntent().getSerializableExtra("similar_products");
if (similarProducts != null && !similarProducts.isEmpty()) {
searchQueryText.setText("图片搜索结果");
searchAdapter.updateData(similarProducts);
findViewById(R.id.no_results_text).setVisibility(View.GONE);
resultsRecyclerView.setVisibility(View.VISIBLE);
} else {
searchQueryText.setText("图片搜索结果");
findViewById(R.id.no_results_text).setVisibility(View.VISIBLE);
resultsRecyclerView.setVisibility(View.GONE);
}
} else {
// 文本搜索结果(原有逻辑)
if (query != null) {
searchQueryText.setText("搜索结果: " + query);
List<Product> searchResults = searchProducts(query);
if (searchResults.isEmpty()) {
findViewById(R.id.no_results_text).setVisibility(View.VISIBLE);
resultsRecyclerView.setVisibility(View.GONE);
} else {
findViewById(R.id.no_results_text).setVisibility(View.GONE);
resultsRecyclerView.setVisibility(View.VISIBLE);
searchAdapter.updateData(searchResults);
}
} else {
// 处理没有查询参数的情况
searchQueryText.setText("搜索结果");
findViewById(R.id.no_results_text).setVisibility(View.VISIBLE);
resultsRecyclerView.setVisibility(View.GONE);
}
}
}
private List<Product> searchProducts(String keyword) {
List<Product> results = new ArrayList<>();
// 这里使用模拟数据,实际应该从数据库或网络加载
List<Product> allProducts = getMockProducts();
for (Product product : allProducts) {
if (product.getName().toLowerCase().contains(keyword.toLowerCase()) ||
product.getDescription().toLowerCase().contains(keyword.toLowerCase()) ||
product.getCategory().toLowerCase().contains(keyword.toLowerCase())) {
results.add(product);
}
}
return results;
}
private List<Product> getMockProducts() {
List<Product> products = new ArrayList<>();
products.add(new Product("1", "Java编程思想", "计算机专业教材", "学习资料", 45.0, ""));
products.add(new Product("2", "高等数学教材", "大学数学课本", "学习资料", 30.0, ""));
products.add(new Product("3", "笔记本电脑", "二手联想笔记本", "数码产品", 1200.0, ""));
products.add(new Product("4", "台灯", "护眼学习台灯", "生活用品", 25.0, ""));
products.add(new Product("5", "Python入门", "编程学习书籍", "学习资料", 35.0, ""));
return products;
}
}

@ -0,0 +1,64 @@
package com.startsmake.llrisetabbardemo.adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.startsmake.llrisetabbardemo.R;
import com.startsmake.llrisetabbardemo.model.Product;
import java.util.List;
public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder> {
private List<Product> productList;
public SearchAdapter(List<Product> productList) {
this.productList = productList;
}
public void updateData(List<Product> newList) {
this.productList = newList;
notifyDataSetChanged();
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_product, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Product product = productList.get(position);
holder.productName.setText(product.getName());
holder.productDescription.setText(product.getDescription());
holder.productCategory.setText(product.getCategory());
holder.productPrice.setText(String.format("¥%.2f", product.getPrice()));
}
@Override
public int getItemCount() {
return productList.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
TextView productName;
TextView productDescription;
TextView productCategory;
TextView productPrice;
public ViewHolder(@NonNull View itemView) {
super(itemView);
productName = itemView.findViewById(R.id.product_name);
productDescription = itemView.findViewById(R.id.product_description);
productCategory = itemView.findViewById(R.id.product_category);
productPrice = itemView.findViewById(R.id.product_price);
}
}
}

@ -0,0 +1,69 @@
package com.startsmake.llrisetabbardemo.model;
import java.io.Serializable;
import java.util.Objects;
public class Product implements Serializable {
private String id;
private String name;
private String description;
private String category;
private double price;
private String imageUrl;
public Product() {
}
public Product(String id, String name, String description, String category, double price, String imageUrl) {
this.id = id;
this.name = name;
this.description = description;
this.category = category;
this.price = price;
this.imageUrl = imageUrl;
}
// Getter 和 Setter 方法
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public String getCategory() { return category; }
public void setCategory(String category) { this.category = category; }
public double getPrice() { return price; }
public void setPrice(double price) { this.price = price; }
public String getImageUrl() { return imageUrl; }
public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; }
// 添加 equals 和 hashCode 方法
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Product product = (Product) o;
return Objects.equals(id, product.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
// 可选:添加 toString 方法便于调试
@Override
public String toString() {
return "Product{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", category='" + category + '\'' +
", price=" + price +
'}';
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<stroke
android:width="0.8dp"
android:color="#999999" />
<corners android:radius="18dp" />
</shape>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f5f5f5" />
<corners android:radius="20dp" />
<stroke
android:width="1dp"
android:color="#e0e0e0" />
</shape>

@ -0,0 +1,176 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white">
<!-- 搜索栏 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFDD59"
android:orientation="horizontal"
android:padding="12dp">
<!-- 返回按钮 -->
<ImageButton
android:id="@+id/back_button"
android:layout_width="24dp"
android:layout_height="50dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_back"
android:scaleType="centerInside"
android:padding="6dp"
android:contentDescription="返回" />
<!-- 搜索框 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:alpha="0.8"
android:background="@drawable/rounded_background1"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp">
<!-- 摄像头按钮 -->
<ImageButton
android:id="@+id/camera_button"
android:layout_width="23dp"
android:layout_height="24dp"
android:layout_marginStart="4dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="0.5dp"
android:scaleType="centerInside"
android:src="@android:drawable/ic_menu_camera"
android:contentDescription="拍照搜索" />
<EditText
android:id="@+id/search_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:background="@null"
android:hint="搜索教材、数码、生活用品..."
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"
android:textColor="#333333"
android:textColorHint="#999999"
android:textSize="14sp"
android:cursorVisible="true"
android:focusable="true"
android:focusableInTouchMode="true"/>
<!-- 搜索按钮 - 放在输入框外面右侧 -->
<TextView
android:id="@+id/search_button"
android:layout_width="50dp"
android:layout_height="27dp"
android:layout_marginStart="2dp"
android:layout_marginTop="0dp"
android:gravity="center"
android:text="搜索"
android:textColor="#333333"
android:textSize="14sp"
android:textStyle="bold"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
</LinearLayout>
<!-- 内容区域 -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- 历史搜索 -->
<TextView
android:id="@+id/history_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="历史搜索"
android:textColor="#333333"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginBottom="12dp" />
<!-- 历史记录容器 - 使用 FlexboxLayout -->
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/history_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flexWrap="wrap"
app:alignItems="flex_start"
app:justifyContent="flex_start" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<!-- 展开/收起按钮 -->
<TextView
android:id="@+id/expand_history_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="展开更多"
android:textColor="#666666"
android:textSize="12sp"
android:padding="8dp"
android:visibility="gone" />
<!-- 清空历史 -->
<TextView
android:id="@+id/clear_history_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="清空历史记录"
android:textColor="#666666"
android:textSize="12sp"
android:padding="8dp" />
</LinearLayout>
<!-- 猜你可能在找 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="猜你可能在找"
android:textColor="#333333"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="24dp"
android:layout_marginBottom="12dp" />
<!-- 推荐容器 - 使用 FlexboxLayout -->
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/recommend_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flexWrap="wrap"
app:alignItems="flex_start"
app:justifyContent="flex_start" />
</LinearLayout>
</ScrollView>
</LinearLayout>

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white">
<!-- 搜索栏 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFDD59"
android:orientation="horizontal"
android:padding="16dp">
<ImageButton
android:id="@+id/back_button"
android:layout_width="20dp"
android:layout_height="28dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_back"
android:scaleType="centerInside"
android:padding="6dp"
android:contentDescription="返回" />
<TextView
android:id="@+id/search_query_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="16dp"
android:gravity="center_vertical"
android:text="搜索结果"
android:textColor="#333333"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<!-- 搜索结果 -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/results_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp" />
<!-- 无结果提示 -->
<TextView
android:id="@+id/no_results_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="120dp"
android:text="没有找到相关商品"
android:textColor="#666666"
android:textSize="16sp"
android:visibility="gone" />
</LinearLayout>

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="@android:color/white"
android:layout_marginBottom="8dp"
android:elevation="2dp">
<TextView
android:id="@+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="商品名称"
android:textColor="#333333"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/product_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="商品描述"
android:textColor="#666666"
android:textSize="14sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<TextView
android:id="@+id/product_category"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="类别"
android:textColor="#999999"
android:textSize="12sp" />
<TextView
android:id="@+id/product_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="¥0.00"
android:textColor="#ff6b35"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="." />
<cache-path name="cache_files" path="." />
</paths>
Loading…
Cancel
Save