I haven't updated my blog for a while, so I was busy some time ago and failed to write my blog.
In the past few days, the company has made me familiar with the environment and prepared to give the company news next week. First of all, we need to find something similar to this. It's good to see Sohu news, start with the template!
1. first, we need to solve the layout, which is divided into four parts of the news content. The following is a list of news titles belonging to this part. The previous news category uses four buttons. The following list of news titles must use SrollView, for a scrollable view control, the items in it need to use the ListView list. The basic layout has been determined. The figure above is just a few items. You can modify them at that time.
If you want to know more about ListView, recommended blog: http://blog.csdn.net/xys289187120/article/details/6636139
One of the main classes is:
Package com. ifensi. news. information; import java. util. arrayList; import java. util. hashMap; import java. util. iterator; import java. util. map; import org. json. JSONArray; import org. json. JSONObject; import android. app. listActivity; import android. content. context; import android. content. intent; import android. graphics. pixelFormat; import android. OS. bundle; import android. view. layoutInflater; import android. view. view; Import android. view. viewGroup; import android. view. window; import android. view. windowManager; import android. view. view. onClickListener; import android. widget. adapterView; import android. widget. listView; import android. widget. simpleAdapter; import android. widget. adapterView. onItemClickListener; public class NewsInformation extends ListActivity {/** Called when the activity is first created. */ListView mLi StView = null; ArrayList <Map <String, Object> mData = new ArrayList <Map <String, Object> (); private View mainLayout; private LayoutInflater inflater; @ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // remove the title requestWindowFeature (Window. FEATURE_NO_TITLE); // set the window to full screen getWindow (). setFlags (WindowManager. layoutParams. FLAG_FULLSCREEN, WindowManager. layoutParams. FLA G_FULLSCREEN); // set the window to a translucent getWindow (). setFormat (PixelFormat. TRANSLUCENT); inflater = (LayoutInflater) this. getApplicationContext (). getSystemService (Context. LAYOUT_INFLATER_SERVICE); mainLayout = inflater. inflate (R. layout. navigation_container, null); ButtomButtonOnClickListener buttomButtonOnClickListener = new ButtomButtonOnClickListener (); mainLayout. findViewById (R. id. btn_guide ). setOnClickListener (TomButtonOnClickListener); mainLayout. findViewById (R. id. btn_model ). setOnClickListener (buttomButtonOnClickListener); mainLayout. findViewById (R. id. btn_news ). setOnClickListener (buttomButtonOnClickListener); mainLayout. findViewById (R. id. btn_search ). setOnClickListener (buttomButtonOnClickListener); mainLayout. findViewById (R. id. btn_more ). setOnClickListener (buttomButtonOnClickListener); // obtain json data and wait for the interface to implement Strin G [] mListTitle = {"name", "gender", "Age", "Place of Residence", "email", "name", "gender", "Age ", "Place of Residence", "Mailbox"}; String [] mListStr = {"Yan Dong DIDO", "male", "25", "Beijing", "yandong_dido@126.com ", "Yan Dong DIDO", "male", "25", "Beijing", "yandong_dido@126.com"}; this. getListViewContext (mListTitle, mListStr);} public String getJson () {String jsonString = ""; try {JSONObject result = new JSONObject (jsonString); int num = result. length (); JSONArray nameList = Result. getJSONArray ("name"); int length = nameList. length (); String aa = ""; for (int I = 0; I <length; I ++) {JSONObject obj = nameList. getJSONObject (I); aa = aa + obj. getString ("name") + "|";} Iterator <?> It = result. keys (); String aa2 = ""; String bb2 = null; while (it. hasNext () {bb2 = (String) it. next (). toString (); aa2 = aa2 + result. getString (bb2);} return aa;} catch (Exception e) {} return null;} public ListView getListViewContext (String mListTitle [], String mListStr []) {mListView = getListView (); int lengh = mListTitle. length; for (int I = 0; I <lengh; I ++) {Map <String, Object> item = new HashMap <Str Ing, Object> (); item. put ("title", mListTitle [I]); item. put ("text", mListStr [I]); mData. add (item);} SimpleAdapter adapter = new SimpleAdapter (this, mData, android. r. layout. simple_list_item_2, new String [] {"title", "text"}, new int [] {android. r. id. text1, android. r. id. text2}); setListAdapter (adapter); mListView. setOnItemClickListener (new OnItemClickListener () {@ Overridepublic void onItemClick (AdapterVi Ew <?> AdapterView, View view, int position, long id) {Intent intent = new Intent (); intent. setClass (NewsInformation. this, NewsContext. class); Bundle bundle = new Bundle (); bundle. putString ("id", "aaaa"); intent. putExtras (bundle); startActivity (intent); // Toast. makeText (TitleList. this, "you have selected the title:" + // mListTitle [position] + "content:" + mListStr [position], // Toast. LENGTH_LONG ). show () ;}}); return mListView;} private class ButtomButtonOnClickListener implements OnClickListener {@ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. btn_guide: // startGoogleMap (); break; case R. id. btn_model: break; case R. id. btn_news: break; case R. id. btn_search: break; case R. id. btn_more: break ;}} public void setLastBottomButtomVisibility (int v) {mainLayout. findViewById (R. id. btn_more ). setVisibility (v);} public void setContentView (int layoutResID) {View v = this. inflater. inflate (layoutResID, null); ViewGroup container = (ViewGroup) mainLayout. findViewById (R. id. container); container. addView (v); super. setContentView (mainLayout );}}
The file layout is relatively simple:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent" android:gravity="top"><LinearLayout android:id="@+id/buttom_buttons"android:layout_width="fill_parent" android:layout_height="wrap_content"android:orientation="horizontal"><Button android:id="@+id/btn_guide" android:layout_width="wrap_content"android:layout_weight="1" android:layout_height="wrap_content"android:background="@drawable/button_guide" /><Button android:id="@+id/btn_news" android:layout_width="wrap_content"android:layout_weight="1" android:layout_height="wrap_content"android:background="@drawable/button_news" /><Button android:id="@+id/btn_model" android:layout_width="wrap_content"android:layout_weight="1" android:layout_height="wrap_content"android:background="@drawable/button_model" /><Button android:id="@+id/btn_search" android:layout_width="wrap_content"android:layout_weight="1" android:layout_height="wrap_content"android:background="@drawable/button_search" /><Button android:id="@+id/btn_more" android:layout_width="wrap_content"android:layout_weight="1" android:layout_height="wrap_content"android:background="@drawable/button_search" android:visibility="gone" /></LinearLayout><FrameLayout android:id="@+id/container"android:layout_weight="1" android:layout_width="fill_parent"android:layout_height="wrap_content"><ScrollView android:id="@+id/scrollView"android:layout_below="@+id/title_bar" android:layout_width="fill_parent"android:layout_height="fill_parent"></ScrollView></FrameLayout></LinearLayout>
2. Add some basic events for the rest: (1) Click to view news; (2) slide the screen to display different news lists.
The above is a relatively basic functional design. Here, the news list is the JSON data obtained through the request interface. Here, the interface must be completed by a colleague before implementation.
Slide screen events are directly used from a blog and are not completely embedded in my program.
The project has not been completed yet, but it has not been fully implemented yet. Later ~~