完善论坛-热榜布局

0515
panqihua 4 years ago
parent 5be83fe731
commit 653ac9520c
  1. 57
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumHotFragment.java
  2. 80
      app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml
  3. 2
      app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml
  4. 4
      app/src/main/res/values-en-rUS/strings.xml
  5. 4
      app/src/main/res/values-zh-rCN/strings.xml
  6. 4
      app/src/main/res/values/strings.xml

@ -1,7 +1,21 @@
package com.community.pocket.ui.main.ui.forum;
import android.content.Context;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.community.pocket.R;
import com.community.pocket.ui.main.TestMainFragment;
import com.community.pocket.ui.BaseFragment;
import org.xutils.view.annotation.ContentView;
@ -9,12 +23,45 @@ import org.xutils.view.annotation.ContentView;
* 热门帖子
*/
@ContentView(R.layout.forum_hot_fragment)
public class ForumHotFragment extends TestMainFragment {
public class ForumHotFragment extends BaseFragment {
@NonNull
@Override
protected int viewId() {
return R.id.text_hot;
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
//TODO 测试数据
addRank(view, R.id.active_user, R.id.active_user_text, new String[]{"aaaa", "bbbb", "ccccc"});
addRank(view, R.id.hot_topic, R.id.hot_topic_text, new String[]{"xxxx", "123", "fuckadsf"});
addRank(view, R.id.hot_events, R.id.hot_events_text, new String[]{"sadf", "fsd12", "123f"});
return view;
}
/**
* @param constraintId 约束布局id
* @param textId 标题布局id
* @param ranks 排名数组
*/
private void addRank(View view, @IdRes int constraintId, @IdRes int textId, String[] ranks) {
ConstraintLayout layout = view.findViewById(constraintId);
Context context = view.getContext();
int id = 0;
for (int i = 1; i <= ranks.length; i++) {
TextView textView = new TextView(context);
textView.setText(context.getString(R.string.hot_rank, i, ranks[i - 1]));
//文本居中
textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
//字体大小
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setId(View.generateViewId());
//设置约束
ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layoutParams.topToBottom = i == 1 ? textId : id;
layoutParams.setMargins(0, 10, 0, 0);
textView.setLayoutParams(layoutParams);
layout.addView(textView);
id = textView.getId();
}
}
}

@ -1,13 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".ui.main.ui.forum.ForumHotFragment">
<TextView
android:id="@+id/text_hot"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="match_parent"
tools:ignore="UselessParent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/active_user"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="@dimen/size_50"
android:background="@drawable/border">
<TextView
android:id="@+id/active_user_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="@string/active_user"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/hot_topic"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="@dimen/size_50"
android:background="@drawable/border">
<TextView
android:id="@+id/hot_topic_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="@string/hot_topic"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/hot_events"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="@dimen/size_50"
android:background="@drawable/border">
<TextView
android:id="@+id/hot_events_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="@string/hot_events"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>

@ -4,6 +4,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- TODO 公告栏添加箭头图标引导滑动-->
<TextView
android:id="@+id/notice_title"
android:layout_width="wrap_content"

@ -50,4 +50,8 @@
<string name="notice_content_load">load notice content.....</string>
<string name="notice_time">time:%1s</string>
<string name="dateformat">yyyy-MM-dd HH:mm:ss</string>
<string name="active_user">Active User</string>
<string name="hot_topic">Hot Topic</string>
<string name="hot_events">Hot Events</string>
<string name="hot_rank">%1d.%2s</string>
</resources>

@ -50,4 +50,8 @@
<string name="notice_content_load">加载公告内容中。。。。</string>
<string name="notice_time">公告时间:%1s</string>
<string name="dateformat">yyyy-MM-dd HH:mm:ss</string>
<string name="active_user">活跃用户</string>
<string name="hot_topic">热门动态</string>
<string name="hot_events">热门活动</string>
<string name="hot_rank">%1d.%2s</string>
</resources>

@ -51,6 +51,10 @@
<string name="notice_content_load">load notice content.....</string>
<string name="notice_time">time:%1s</string>
<string name="dateformat">yyyy-MM-dd HH:mm:ss</string>
<string name="active_user">Active User</string>
<string name="hot_topic">Hot Topic</string>
<string name="hot_events">Hot Events</string>
<string name="hot_rank">%1d.%2s</string>
<!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save