parent
653ac9520c
commit
bbf4209f3f
@ -1,19 +1,62 @@ |
|||||||
package com.community.pocket.ui.main.ui.forum; |
package com.community.pocket.ui.main.ui.forum; |
||||||
|
|
||||||
|
import android.os.Bundle; |
||||||
|
import android.text.format.DateFormat; |
||||||
|
import android.view.View; |
||||||
|
import android.view.ViewGroup; |
||||||
|
import android.widget.LinearLayout; |
||||||
|
import android.widget.TextView; |
||||||
|
|
||||||
|
import androidx.annotation.NonNull; |
||||||
|
import androidx.annotation.Nullable; |
||||||
|
|
||||||
import com.community.pocket.R; |
import com.community.pocket.R; |
||||||
import com.community.pocket.ui.main.TestMainFragment; |
import com.community.pocket.ui.BaseFragment; |
||||||
|
|
||||||
import org.xutils.view.annotation.ContentView; |
import org.xutils.view.annotation.ContentView; |
||||||
|
import org.xutils.view.annotation.ViewInject; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
/** |
/** |
||||||
* 最新帖子 |
* 最新帖子 |
||||||
*/ |
*/ |
||||||
@ContentView(R.layout.forum_new_fragment) |
@ContentView(R.layout.forum_new_fragment) |
||||||
public class ForumNewFragment extends TestMainFragment { |
public class ForumNewFragment extends BaseFragment { |
||||||
|
|
||||||
|
@ViewInject(R.id.post_layout) |
||||||
|
private LinearLayout layout; |
||||||
|
|
||||||
@Override |
@Override |
||||||
protected int viewId() { |
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
||||||
return R.id.text_new; |
super.onViewCreated(view, savedInstanceState); |
||||||
|
|
||||||
|
loadPost(view); |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 加载最新帖子 |
||||||
|
*/ |
||||||
|
private void loadPost(View view) { |
||||||
|
//TODO 测试数据
|
||||||
|
for (int i = 0; i < 10; i++) { |
||||||
|
View childView = View.inflate(getContext(), R.layout.post, null); |
||||||
|
TextView title = childView.findViewById(R.id.post_title); |
||||||
|
title.setText("标题" + i); |
||||||
|
TextView content = childView.findViewById(R.id.post_content); |
||||||
|
content.setText("内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容" + i); |
||||||
|
TextView author = childView.findViewById(R.id.poster); |
||||||
|
author.setText(getString(R.string.poster, "发帖人" + i)); |
||||||
|
TextView time = childView.findViewById(R.id.post_time); |
||||||
|
Date date = new Date(); |
||||||
|
date.setTime(System.currentTimeMillis()); |
||||||
|
time.setText(getString(R.string.post_time, DateFormat.format(getString(R.string.dateformat), date))); |
||||||
|
ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); |
||||||
|
layoutParams.setMargins(0, 0, 0, 50); |
||||||
|
childView.setLayoutParams(layoutParams); |
||||||
|
layout.addView(childView); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
@ -0,0 +1,68 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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" |
||||||
|
android:background="@drawable/border"> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/post_title" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:gravity="center" |
||||||
|
android:textSize="18sp" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" /> |
||||||
|
|
||||||
|
<ImageView |
||||||
|
android:id="@+id/headimg" |
||||||
|
android:layout_width="100dp" |
||||||
|
android:layout_height="100dp" |
||||||
|
android:layout_marginStart="32dp" |
||||||
|
android:layout_marginTop="16dp" |
||||||
|
android:contentDescription="@string/headimg" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toBottomOf="@id/post_title" |
||||||
|
app:srcCompat="@drawable/border" /> |
||||||
|
|
||||||
|
<EditText |
||||||
|
android:id="@+id/post_content" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="0dp" |
||||||
|
android:layout_marginStart="24dp" |
||||||
|
android:background="@drawable/border" |
||||||
|
android:ems="10" |
||||||
|
android:enabled="false" |
||||||
|
android:hint="@string/load_post_content" |
||||||
|
android:importantForAutofill="no" |
||||||
|
android:inputType="none|textMultiLine" |
||||||
|
android:maxLines="4" |
||||||
|
app:layout_constraintBottom_toBottomOf="@id/headimg" |
||||||
|
app:layout_constraintStart_toEndOf="@id/headimg" |
||||||
|
app:layout_constraintTop_toTopOf="@id/headimg" |
||||||
|
tools:layout_constraintEnd_toEndOf="parent" |
||||||
|
tools:layout_constraintStart_toEndOf="@id/headimg" /> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/poster" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_marginTop="16dp" |
||||||
|
android:gravity="center" |
||||||
|
android:textSize="18sp" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toBottomOf="@id/headimg" /> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/post_time" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:gravity="center" |
||||||
|
android:textSize="18sp" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toBottomOf="@id/poster" /> |
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
Loading…
Reference in new issue