Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent"
  7. android:gravity="right"
  8. android:id="@+id/fillable_area"
  9. >
  10. <TableLayout
  11. android:gravity="right"
  12. android:id="@+id/table_header"
  13. android:layout_width="fill_parent"
  14. android:layout_height="wrap_content"/>
  15. <ScrollView
  16. android:layout_width="fill_parent"
  17. android:layout_height="wrap_content">
  18.  
  19. <LinearLayout android:orientation="horizontal"
  20. android:layout_width="match_parent"
  21. android:layout_height="match_parent">
  22.  
  23. <HorizontalScrollView
  24. android:id="@+id/scroller"
  25. android:layout_width="0dp"
  26. android:layout_weight="1"
  27. android:layout_height="wrap_content">
  28.  
  29. <TableLayout
  30. android:id="@+id/scrollable_part"
  31. android:layout_width="fill_parent"
  32. android:layout_height="fill_parent"/>
  33. </HorizontalScrollView>
  34.  
  35. <TableLayout
  36. android:id="@+id/scrollable_part2"
  37. android:layout_width="wrap_content"
  38.  
  39. android:layout_height="wrap_content"/>
  40. </LinearLayout>
  41.  
  42. </ScrollView>
  43.  
  44. </LinearLayout>
  45.  
  46. package com.examp.swap_items;
  47. import java.util.ArrayList;
  48. import java.util.List;
  49.  
  50. import android.R.layout;
  51. import android.app.Activity;
  52. import android.os.Bundle;
  53. import android.view.Menu;
  54. import android.view.MenuItem;
  55. import android.view.View;
  56. import android.view.ViewGroup;
  57. import android.widget.Button;
  58. import android.widget.HorizontalScrollView;
  59. import android.widget.TableLayout;
  60. import android.widget.TableRow;
  61. import android.widget.TextView;
  62. import android.app.Activity;
  63. import android.graphics.Color;
  64. import android.os.Bundle;
  65. import android.view.ContextThemeWrapper;
  66. import android.view.Gravity;
  67. import android.widget.TableLayout;
  68. import android.widget.TableRow;
  69. import android.widget.TableRow.LayoutParams;
  70. import android.widget.TextView;
  71. import android.app.Activity;
  72.  
  73. public class MainActivity extends Activity {
  74. private boolean showSummaries;
  75.  
  76. private TableLayout summaryTable;
  77. private TableLayout frozenTable;
  78. private TableLayout contentTable;
  79. private Button backButton ;
  80. private HorizontalScrollView hor;
  81. private TextView recyclableTextView;
  82.  
  83. private String[] allColors ;
  84. @Override
  85. protected void onCreate(Bundle savedInstanceState) {
  86. super.onCreate(savedInstanceState);
  87. setContentView(R.layout.activity_main);
  88.  
  89.  
  90. Color[] colors = {};
  91.  
  92.  
  93. TableRow.LayoutParams wrapWrapTableRowParams = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  94. int[] fixedColumnWidths = new int[]{20,20, 20,20, 20, 20};
  95.  
  96.  
  97. int[] scrollableColumnWidths = new int[]{20,20, 20, 20, 20, 20};
  98. int fixedRowHeight = 50;
  99. int fixedHeaderHeight = 60;
  100. TableRow row = new TableRow(this);
  101. //header (fixed vertically)
  102. TableLayout header=(TableLayout)findViewById(R.id.table_header);
  103. row.setLayoutParams(wrapWrapTableRowParams);
  104. row.setGravity(Gravity.CENTER);
  105. row.setBackgroundColor(Color.WHITE);
  106. row.addView(makeTableRowWithText("col1",fixedColumnWidths[0],fixedHeaderHeight));
  107. row.addView(makeTableRowWithText("col2",fixedColumnWidths[1],fixedHeaderHeight));
  108. row.addView(makeTableRowWithText("col3",fixedColumnWidths[2],fixedHeaderHeight));
  109. row.addView(makeTableRowWithText("col4",fixedColumnWidths[3],fixedHeaderHeight));
  110. row.addView(makeTableRowWithText("col5",fixedColumnWidths[4],fixedHeaderHeight));
  111. // row.addView(makeTableRowWithText("col6", fixedColumnWidths[5],fixedHeaderHeight));
  112. header.addView(row);
  113.  
  114.  
  115. hor = (HorizontalScrollView)findViewById(R.id.scroller);
  116. hor.postDelayed(new Runnable(){
  117. public void run() {
  118. hor.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
  119. }},1L);
  120.  
  121.  
  122. TableLayout fixedColumn = (TableLayout) findViewById(R.id.scrollable_part2);
  123. //rest of the table (within a scroll view)
  124. TableLayout scrollablePart = (TableLayout)findViewById(R.id.scrollable_part);
  125. for(int i = 0; i < 10; i++) {
  126. TextView fixedView = makeTableRowWithText("fixed number " + i, scrollableColumnWidths[0], fixedRowHeight);
  127. fixedView.setBackgroundColor(Color.GREEN);
  128. fixedView.setGravity(Gravity.RIGHT);
  129. fixedColumn.addView(fixedView);
  130. row = new TableRow(this);
  131. row.setLayoutParams(wrapWrapTableRowParams);
  132. row.setGravity(Gravity.LEFT);
  133. if(i==1)row.setBackgroundColor(Color.RED);
  134. if(i==2)row.setBackgroundColor(Color.MAGENTA);
  135. if(i==3)row.setBackgroundColor(Color.YELLOW);
  136. if(i==4)row.setBackgroundColor(Color.GRAY);
  137. if(i==5)row.setBackgroundColor(Color.LTGRAY);
  138. if(i==6)row.setBackgroundColor(Color.WHITE);
  139. if(i==7)row.setBackgroundColor(Color.CYAN);
  140. if(i==8)row.setBackgroundColor(Color.TRANSPARENT);
  141. if(i==9)row.setBackgroundColor(Color.MAGENTA);
  142. row.addView(makeTableRowWithText("scroll 1", scrollableColumnWidths[1], fixedRowHeight));
  143. row.addView(makeTableRowWithText("scroll 2", scrollableColumnWidths[1], fixedRowHeight));
  144. row.addView(makeTableRowWithText("scroll 3", scrollableColumnWidths[2], fixedRowHeight));
  145. row.addView(makeTableRowWithText("scroll 4", scrollableColumnWidths[3], fixedRowHeight));
  146. row.addView(makeTableRowWithText("scroll 5", scrollableColumnWidths[4], fixedRowHeight));
  147. row.addView(makeTableRowWithText("scroll 6", scrollableColumnWidths[5], fixedRowHeight));
  148. scrollablePart.addView(row);
  149. }
  150. }
  151. public TextView makeTableRowWithText(String text, int widthInPercentOfScreenWidth, int fixedHeightInPixels) {
  152. int screenWidth = getResources().getDisplayMetrics().widthPixels;
  153. recyclableTextView = new TextView(this);
  154. recyclableTextView.setText(text);
  155. recyclableTextView.setTextColor(Color.BLACK);
  156. recyclableTextView.setTextSize(20);
  157. recyclableTextView.setWidth(widthInPercentOfScreenWidth * screenWidth / 100);
  158. recyclableTextView.setHeight(fixedHeightInPixels);
  159. return recyclableTextView;
  160. }
  161.  
  162. @Override
  163. public boolean onCreateOptionsMenu(Menu menu) {
  164. // Inflate the menu; this adds items to the action bar if it is present.
  165. getMenuInflater().inflate(R.menu.main, menu);
  166. return true;
  167. }
  168.  
  169. @Override
  170. public boolean onOptionsItemSelected(MenuItem item) {
  171. // Handle action bar item clicks here. The action bar will
  172. // automatically handle clicks on the Home/Up button, so long
  173. // as you specify a parent activity in AndroidManifest.xml.
  174. int id = item.getItemId();
  175. if (id == R.id.action_settings) {
  176. return true;
  177. }
  178. return super.onOptionsItemSelected(item);
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement