From c6bbe55d9018117fd2189a4342a449f2351099ab Mon Sep 17 00:00:00 2001 From: Toyga <330282372@qq.com> Date: Tue, 9 Nov 2021 22:44:24 +0800 Subject: [PATCH] CommunityFragment finished! --- .../app/src/main/AndroidManifest.xml | 5 +- .../InvitationPageFragmentAdapter.java | 30 +++++ .../Fragment/CommunityFragment.java | 124 ++++++++++++------ .../Fragment/InvitationChannelFragment.java | 49 +++++++ .../res/drawable/invitation_tab_selector.xml | 41 ++++++ .../main/res/drawable/search_background.xml | 13 ++ .../main/res/layout/activity_go_answer.xml | 12 +- .../res/layout/activity_send_invitation.xml | 2 +- .../res/layout/activity_send_question.xml | 2 +- .../main/res/layout/fragment_community.xml | 86 +++++++++++- .../layout/fragment_invitation_channel.xml | 17 +++ .../src/main/res/layout/invitation_tab_rb.xml | 13 ++ .../app/src/main/res/mipmap-mdpi/img_add.png | Bin 0 -> 1014 bytes .../res/mipmap-mdpi/img_go_answer_return.png | Bin 0 -> 399 bytes .../src/main/res/mipmap-mdpi/img_search.png | Bin 0 -> 1069 bytes .../res/mipmap-xhdpi/channel_down_narrow.png | Bin 0 -> 423 bytes 16 files changed, 339 insertions(+), 55 deletions(-) create mode 100644 Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Adapter/InvitationPageFragmentAdapter.java create mode 100644 Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Fragment/InvitationChannelFragment.java create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/drawable/invitation_tab_selector.xml create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/drawable/search_background.xml create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/layout/fragment_invitation_channel.xml create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/layout/invitation_tab_rb.xml create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_add.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_go_answer_return.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_search.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-xhdpi/channel_down_narrow.png diff --git a/Code/LeudaemiaLikeMe/app/src/main/AndroidManifest.xml b/Code/LeudaemiaLikeMe/app/src/main/AndroidManifest.xml index cd877d1..e8312a5 100644 --- a/Code/LeudaemiaLikeMe/app/src/main/AndroidManifest.xml +++ b/Code/LeudaemiaLikeMe/app/src/main/AndroidManifest.xml @@ -9,8 +9,9 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.LeudaemiaLikeMe"> - - + + + diff --git a/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Adapter/InvitationPageFragmentAdapter.java b/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Adapter/InvitationPageFragmentAdapter.java new file mode 100644 index 0000000..55644c5 --- /dev/null +++ b/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Adapter/InvitationPageFragmentAdapter.java @@ -0,0 +1,30 @@ +package com.example.leudaemialikeme.Adapter; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; + +import com.example.leudaemialikeme.Fragment.InvitationChannelFragment; + +public class InvitationPageFragmentAdapter extends FragmentPagerAdapter { + private String[] channelList; + private FragmentManager fm; + public InvitationPageFragmentAdapter(@NonNull FragmentManager fm, String[] channelList) { + super(fm); + this.channelList = channelList; + this.fm = fm; + } + + @NonNull + @Override + public Fragment getItem(int position) { + String InvitationCategoryTitle = channelList[position]; + return InvitationChannelFragment.newInstance(InvitationCategoryTitle); + } + + @Override + public int getCount() { + return channelList.length; + } +} diff --git a/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Fragment/CommunityFragment.java b/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Fragment/CommunityFragment.java index 846cc53..414a171 100644 --- a/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Fragment/CommunityFragment.java +++ b/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/Fragment/CommunityFragment.java @@ -1,65 +1,107 @@ package com.example.leudaemialikeme.Fragment; import android.os.Bundle; +import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.HorizontalScrollView; +import android.widget.RadioButton; +import android.widget.RadioGroup; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.viewpager.widget.ViewPager; +import com.example.leudaemialikeme.Adapter.InvitationPageFragmentAdapter; import com.example.leudaemialikeme.R; -/** - * A simple {@link Fragment} subclass. - * Use the {@link CommunityFragment#newInstance} factory method to - * create an instance of this fragment. - */ -public class CommunityFragment extends Fragment { - - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; +public class CommunityFragment extends Fragment implements ViewPager.OnPageChangeListener { + private static final String ARG_CHANNEL_LIST = "channel_list"; + private View view=null; // 碎片的布局实例 + private ViewPager viewPager; //内导航的碎片的容器 + private RadioGroup rgChannel=null; // 内导航由单选按钮组构成 + private HorizontalScrollView hvChannel=null; //单选按钮组可滚动动 + private String[] channelList = {"关注","全部","经验","扫雷","康复","科普","问答"}; //默认的内导航栏目 + private InvitationPageFragmentAdapter adapter; //viewPager 的适配器 public CommunityFragment() { // Required empty public constructor } - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment CommunityFragment. - */ - // TODO: Rename and change types and number of parameters - public static CommunityFragment newInstance(String param1, String param2) { - CommunityFragment fragment = new CommunityFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + if(view==null){ + view=inflater.inflate(R.layout.fragment_community, container, false); + viewPager=(ViewPager)view.findViewById(R.id.vpNewsList); + initViewPager(); //设置 ViewPager + + rgChannel=(RadioGroup)view.findViewById(R.id.rgChannel); + hvChannel=(HorizontalScrollView)view.findViewById(R.id.hvChannel); + initTab(inflater); + + rgChannel.setOnCheckedChangeListener( + new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + viewPager.setCurrentItem(checkedId); + } + } + ); + } + return view; } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); + private void initTab(LayoutInflater inflater) { + for(int i=0;i + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/drawable/search_background.xml b/Code/LeudaemiaLikeMe/app/src/main/res/drawable/search_background.xml new file mode 100644 index 0000000..f814595 --- /dev/null +++ b/Code/LeudaemiaLikeMe/app/src/main/res/drawable/search_background.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/layout/activity_go_answer.xml b/Code/LeudaemiaLikeMe/app/src/main/res/layout/activity_go_answer.xml index 2c2756a..9c700f9 100644 --- a/Code/LeudaemiaLikeMe/app/src/main/res/layout/activity_go_answer.xml +++ b/Code/LeudaemiaLikeMe/app/src/main/res/layout/activity_go_answer.xml @@ -15,14 +15,12 @@ android:padding="20dp" android:orientation="horizontal"> - + android:layout_height="18dp" + android:background="@mipmap/img_go_answer_return" + android:layout_marginRight="100dp" + /> diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/layout/activity_send_question.xml b/Code/LeudaemiaLikeMe/app/src/main/res/layout/activity_send_question.xml index 0a7e175..77fb769 100644 --- a/Code/LeudaemiaLikeMe/app/src/main/res/layout/activity_send_question.xml +++ b/Code/LeudaemiaLikeMe/app/src/main/res/layout/activity_send_question.xml @@ -53,7 +53,7 @@ android:layout_width="match_parent" android:layout_height="42dp" android:ems="10" - android:maxlength="40" + android:maxLength="40" android:inputType="textPersonName" android:layout_margin="10dp" android:hint="请输入你的问题(10-40个字)" /> diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/layout/fragment_community.xml b/Code/LeudaemiaLikeMe/app/src/main/res/layout/fragment_community.xml index af6457d..d9c675a 100644 --- a/Code/LeudaemiaLikeMe/app/src/main/res/layout/fragment_community.xml +++ b/Code/LeudaemiaLikeMe/app/src/main/res/layout/fragment_community.xml @@ -3,12 +3,92 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:orientation="vertical" tools:context=".Fragment.CommunityFragment"> - - + android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/layout/fragment_invitation_channel.xml b/Code/LeudaemiaLikeMe/app/src/main/res/layout/fragment_invitation_channel.xml new file mode 100644 index 0000000..1f97fb2 --- /dev/null +++ b/Code/LeudaemiaLikeMe/app/src/main/res/layout/fragment_invitation_channel.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/layout/invitation_tab_rb.xml b/Code/LeudaemiaLikeMe/app/src/main/res/layout/invitation_tab_rb.xml new file mode 100644 index 0000000..10097ec --- /dev/null +++ b/Code/LeudaemiaLikeMe/app/src/main/res/layout/invitation_tab_rb.xml @@ -0,0 +1,13 @@ + + + diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_add.png b/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_add.png new file mode 100644 index 0000000000000000000000000000000000000000..d8e75f985910cadc5e79a576c7021180d026fa6c GIT binary patch literal 1014 zcmVPx&ut`KgR9HvFS38W{WDx$w_I06zNDx5|0umsRyMMfUrvy->gn|@Aq#%e#2W6s2 z1SBZPg#wzKgpv-BCG1cd?$h=h3QZr9`6AOQuBTu>-N%1gJl2hCwe-o<z?)Kb;9 zy+m}A$%*J4=iKvafmjoOh+G8lKyKhnk|eLr%*jcOsgss)+#rR_(s;e_0e(yWQ@t1z>4uX}_wz z2;eQ}+=rudJDpCeRIvNX-7x?lj^p#zYN|RPhT*Zg=)2wSoacGRn_N{CMJI{q1#3~~ z+=0UO4FGW*->0fS0=VAq_wSvZoxSpZ0$5mB*fudS@iTxeM0CG%?x)pOEu0k50QiQP zAFgw5=i_9+^hM-r01uTjb_0Njdb?U+hxR!hl@m}FUYsE!*9 z127KYdEQwgB6c%G=0MJyho~j&9W@}!uS1;3%1jw kcx$hqiIMf_Y&w9y0reIPKbFJ%Z2$lO07*qoM6N<$g0ZCFA^-pY literal 0 HcmV?d00001 diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_go_answer_return.png b/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_go_answer_return.png new file mode 100644 index 0000000000000000000000000000000000000000..c5a2b98657076ce56065e373fcd14d422ef33d49 GIT binary patch literal 399 zcmV;A0dW3_P)Px$Nl8ROR9Hvt)=f$SK@bJtSACo;=O!)`PoSWpNCFWR6jT%pVo)Kuf>)WU+Ua#l zT4o>%2m7aBHpz0*@V*HPF{5B9{OjJP}!d7_6#OGh28evH{&VP5``lAc_DT;sC(97Eui7 z5XS)CYYpd{^ChM;=^92z-<|14g=n<-V4PZa@ tJm}iM24cKp`F~^j>wnh~Yyl+=`~Xn7mLV7W;bs5;002ovPDHLkV1fhCp4b2Y literal 0 HcmV?d00001 diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_search.png b/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_search.png new file mode 100644 index 0000000000000000000000000000000000000000..02a18c55a6cb502c69c71ad7db2ff09dd11b04e2 GIT binary patch literal 1069 zcmV+|1k(G7P)Px&=Sf6CR9HvFmtAOFMHI*XXF`n#Dt`1qd?|<)iqh=NT#~k^RjXA5!IubX5la;n z6+h6Xf|!8xLsSGskYW*Og(_&pwrc#KNH8&b&m>XO2Sr2_`cMV!QzY5>%Y@yq-6Xp= z8%PgaxOe7!{O-AD=FAnGW07+lAB6x^)d5J?1^}C@&?f*415oFjw)-MY0rEWW7LnZm zZf+6aTM>D}T6=P-Ad3Qo5S}FY3V=?MgCbHk#*|5xQxFl!VvHHdOhj%2@E^%--usW1 z0{29P|&bbE* z0fZ3VCiy6Udz^D0E++%3+6&;Yi1b-&)6!m4>Q_M`JwS4w_r7mA0C}G86_K4Jdt3E} zIe>DxTr$Q40E5oCt;+#W)h|ijP^nbbb$56FRwx5WDTFXYaua~3opW!r15qxQ`;9R# zk^I1WpLWDzJ7E>zE|Q-D_{TYSNh{;V`P559K5H^tf48Uao#sHL( zevI*fEX&?6Tmv=5(b3V3#+bK6q~>VA7&Ad~#Cv}#>E(HTg^2XT7}uw7UbX!kKsrh7 zNUNYac87EBi^U)oJ(5jMPM$Y4HI>%zQw_$yR-dn`9~Y55*4h_pW2*WlfXCCbh-|Ue zezOon%TsX(VO#1EB(DXKuFg6~snvcGV?2^&+405zs(Jvx>`o{mH(G1IYt(58&}a}s zSQleF-x%|UwRX1Rn~AC(29S2f1hLUtn~w5xvSff(0T-Ij^ZclYq^9(@h}>?i&1-rq z1#kg?VzsvI=o>#Q+lY@bK`O&d$!Gwcsn7 nfm+s55!e61t!M@o`gH#TCHs>w?Fwiz00000NkvXXu0mjf2dnf6 literal 0 HcmV?d00001 diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-xhdpi/channel_down_narrow.png b/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-xhdpi/channel_down_narrow.png new file mode 100644 index 0000000000000000000000000000000000000000..c2ce19fa5f1930894578996d3a77fdd9e0ce9952 GIT binary patch literal 423 zcmeAS@N?(olHy`uVBq!ia0vp^xlUVr}C(sR=B$;TgW)ZkKdiJZ2+{LJ&>^Pd^6l>Tj)lzQ`N5#xp!J@M|N zuVuS7MXeQ4J-ul@bNk_kRePBVV#_s{7+KR>