diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumHotFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumHotFragment.java index 8c50a2b..239722f 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumHotFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumHotFragment.java @@ -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(); + } + } } diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml index b9a49b5..282aec5 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml @@ -1,13 +1,87 @@ - + android:layout_height="match_parent" + tools:ignore="UselessParent"> + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml index ce48b41..8e12c15 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml @@ -4,6 +4,8 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + load notice content..... time:%1s yyyy-MM-dd HH:mm:ss + Active User + Hot Topic + Hot Events + %1d.%2s \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 665d415..f32bc10 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -50,4 +50,8 @@ 加载公告内容中。。。。 公告时间:%1s yyyy-MM-dd HH:mm:ss + 活跃用户 + 热门动态 + 热门活动 + %1d.%2s \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49cab6e..53be6cb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,6 +51,10 @@ load notice content..... time:%1s yyyy-MM-dd HH:mm:ss + Active User + Hot Topic + Hot Events + %1d.%2s