Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.85 KB | None | 0 0
  1. <RelativeLayout android:layout_width="fill_parent"
  2. android:layout_height="fill_parent">
  3.  
  4. <FrameLayout android:id="@+id/logoLayout"
  5. android:layout_width="fill_parent"
  6. android:layout_height="wrap_content">
  7. -- some images
  8. </FrameLayout>
  9.  
  10.  
  11. <RelativeLayout android:layout_width="fill_parent"
  12. android:layout_height="wrap_content"
  13. android:gravity="center"
  14. android:orientation="vertical"
  15. android:layout_below="@+id/logoLayout">
  16.  
  17. Button 1
  18. Button 2
  19. Button 3
  20. Button 4
  21.  
  22. </RelativeLayout>
  23.  
  24. <RelativeLayout android:orientation="horizontal"
  25. android:layout_width="fill_parent"
  26. android:layout_height="wrap_content"
  27. android:layout_margin="5dip"
  28. android:layout_alignParentBottom="true">
  29.  
  30. Button 5
  31. </RelativeLayout>
  32.  
  33. <RelativeLayout>
  34.  
  35. <?xml version="1.0" encoding="utf-8"?>
  36. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  37. android:layout_width="fill_parent"
  38. android:layout_height="fill_parent"
  39. android:background="@drawable/background">
  40.  
  41.  
  42. <!--The header of the page-->
  43. <FrameLayout android:id="@+id/logoLayout"
  44. android:layout_width="fill_parent"
  45. android:layout_height="wrap_content">
  46.  
  47. <ImageView android:id="@+id/logoBackground"
  48. android:src="@drawable/logo_background_small"
  49. android:layout_width="fill_parent"
  50. android:layout_height="wrap_content"/>
  51.  
  52. <ImageView android:id="@+id/logoImage"
  53. android:src="@drawable/logo_small"
  54. android:layout_width="wrap_content"
  55. android:layout_height="wrap_content"
  56. android:layout_gravity="left"
  57. android:gravity="center"
  58. android:padding="3dip"/>
  59.  
  60. <TextView android:layout_width="fill_parent"
  61. android:layout_height="wrap_content"
  62. android:text="@string/tracks"
  63. android:layout_gravity="center"
  64. android:gravity="right"
  65. android:textSize="22dip"
  66. android:textColor="#ffffff"
  67. android:padding="3dip">
  68. </TextView>
  69.  
  70. </FrameLayout>
  71.  
  72.  
  73. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  74. android:layout_width="fill_parent"
  75. android:layout_height="wrap_content"
  76. android:gravity="center"
  77. android:orientation="vertical"
  78. android:layout_below="@+id/logoLayout">
  79.  
  80. <Button android:id="@+id/btn1"
  81. android:layout_height="wrap_content"
  82. android:layout_width="250dip"
  83. android:drawableLeft="@drawable/img_small_btn_look_around"
  84. android:background="@drawable/main_long_menu_button"
  85. android:text="@string/btn1"
  86. android:textSize="18dip"
  87. android:textColor="#ffffff"
  88. android:layout_marginTop="20dip"
  89. android:onClick="btnMyTracksOnClick">
  90. </Button>
  91.  
  92. <Button android:id="@+id/btn2"
  93. android:layout_height="wrap_content"
  94. android:layout_width="250dip"
  95. android:drawableLeft="@drawable/img_small_btn_look_around"
  96. android:background="@drawable/main_long_menu_button"
  97. android:text="@string/btn2"
  98. android:textSize="18dip"
  99. android:textColor="#ffffff"
  100. android:layout_marginTop="20dip"
  101. android:layout_below="@+id/btn1">
  102. </Button>
  103.  
  104. <Button android:id="@+id/btn3"
  105. android:layout_height="wrap_content"
  106. android:layout_width="250dip"
  107. android:drawableLeft="@drawable/img_small_btn_look_around"
  108. android:background="@drawable/main_long_menu_button"
  109. android:text="@string/btn3"
  110. android:textSize="18dip"
  111. android:textColor="#ffffff"
  112. android:layout_marginTop="20dip"
  113. android:layout_below="@+id/btn2">
  114. </Button>
  115.  
  116. <Button android:id="@+id/btn4"
  117. android:layout_height="wrap_content"
  118. android:layout_width="250dip"
  119. android:drawableLeft="@drawable/img_small_btn_look_around"
  120. android:background="@drawable/main_long_menu_button"
  121. android:text="@string/btn4"
  122. android:textSize="18dip"
  123. android:textColor="#ffffff"
  124. android:layout_marginTop="20dip"
  125. android:layout_below="@+id/bt3">
  126. </Button>
  127. </RelativeLayout>
  128.  
  129. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  130. android:orientation="horizontal"
  131. android:layout_width="fill_parent"
  132. android:layout_height="wrap_content"
  133. android:layout_margin="5dip"
  134. android:layout_alignParentBottom="true">
  135.  
  136. <Button android:layout_width="90dip"
  137. android:layout_height="wrap_content"
  138. android:textSize="20dip"
  139. android:textColor="#ffffff"
  140. android:layout_alignParentLeft="true"
  141. android:background="@drawable/sett_menu_button"
  142. android:text="@string/back"
  143. android:layout_marginLeft="3dip"/>
  144.  
  145. </RelativeLayout>
  146.  
  147. </RelativeLayout>
  148.  
  149. <RelativeLayout android:layout_width="fill_parent"
  150. android:layout_height="wrap_content"
  151. android:gravity="center"
  152. android:orientation="vertical"
  153. android:layout_below="@+id/logoLayout">
  154.  
  155. Button 1
  156. Button 2
  157. Button 3
  158. Button 4
  159.  
  160. </RelativeLayout>
  161.  
  162. <LinearLayout android:layout_width="fill_parent"
  163. android:layout_height="wrap_content"
  164. android:gravity="center"
  165. android:orientation="vertical"
  166. android:layout_below="@+id/logoLayout">
  167.  
  168. <!-- example button -->
  169. <Button android:layout_width="fill_parent"
  170. android:layout_height="wrap_content" android:layout_weight="1"></Button>
  171. </LinearLayout>
  172.  
  173. ------- parent container top ------------
  174. |
  175. |
  176. |
  177. [label1 (auto expand)]
  178. |
  179. |
  180. |
  181. [label2 (fixed height)]
  182. ------- parent container bottom ------------
  183.  
  184. package com.zhang.relodemo;
  185.  
  186. import android.graphics.Color;
  187. import android.support.v7.app.AppCompatActivity;
  188. import android.os.Bundle;
  189. import android.view.Gravity;
  190. import android.view.View;
  191. import android.view.ViewGroup;
  192. import android.widget.RelativeLayout;
  193. import android.widget.TextView;
  194.  
  195. public class MainActivity extends AppCompatActivity {
  196.  
  197. // ---------------------------------------------------
  198. // Member Variables
  199. // ---------------------------------------------------
  200.  
  201. RelativeLayout container;
  202.  
  203. TextView label1;
  204. TextView label2;
  205.  
  206. // ---------------------------------------------------
  207. // Property Methods
  208. // ---------------------------------------------------
  209.  
  210. public RelativeLayout getContainer() {
  211. return container;
  212. }
  213.  
  214. public void setContainer(RelativeLayout container) {
  215. this.container = container;
  216. }
  217.  
  218. public TextView getLabel1() {
  219. return label1;
  220. }
  221.  
  222. public void setLabel1(TextView label1) {
  223. this.label1 = label1;
  224. }
  225.  
  226. public TextView getLabel2() {
  227. return label2;
  228. }
  229.  
  230. public void setLabel2(TextView label2) {
  231. this.label2 = label2;
  232. }
  233.  
  234. // ---------------------------------------------------
  235. // Methods
  236. // ---------------------------------------------------
  237.  
  238. @Override
  239. protected void onCreate(Bundle savedInstanceState) {
  240. super.onCreate(savedInstanceState);
  241.  
  242. initViews();
  243. initLayouts();
  244. addViews();
  245. }
  246.  
  247. void initViews() {
  248. container = new RelativeLayout(this);
  249.  
  250. label1 = new TextView(this);
  251. label1.setText("The quick brown fox jumped over the lazy dog.");
  252. label1.setBackgroundColor(Color.LTGRAY);
  253. label1.setGravity(Gravity.CENTER);
  254. label1.setTextSize(20);
  255.  
  256. label2 = new TextView(this);
  257. label2.setText("Label 2 is a short label compared to label1.It has two lines but take up a fraction of the space.");
  258. label2.setBackgroundColor(Color.GRAY);
  259. label2.setTextSize(20);
  260. label2.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  261. }
  262.  
  263. void initLayouts() {
  264. container.setId(View.generateViewId());
  265.  
  266. label1.setId(View.generateViewId());
  267. label2.setId(View.generateViewId());
  268.  
  269.  
  270. // ---------------------------------------------------
  271. // Parent Container Constraints
  272. // ---------------------------------------------------
  273.  
  274. RelativeLayout.LayoutParams containerLayoutParams = new RelativeLayout.LayoutParams(
  275. ViewGroup.LayoutParams.MATCH_PARENT,
  276. ViewGroup.LayoutParams.MATCH_PARENT
  277. );
  278.  
  279. container.setLayoutParams(containerLayoutParams);
  280.  
  281.  
  282.  
  283. // ---------------------------------------------------
  284. // Label Constraints
  285. // ---------------------------------------------------
  286.  
  287. RelativeLayout.LayoutParams label1LayoutParams = new RelativeLayout.LayoutParams(
  288. ViewGroup.LayoutParams.MATCH_PARENT,
  289. ViewGroup.LayoutParams.MATCH_PARENT
  290. );
  291.  
  292. // --------------------------------------
  293. // THIS IS THE IMPORTANT STEP HERE
  294. //
  295. // It tells label1 to be above label2
  296. // while expanding vertically.
  297. // --------------------------------------
  298. label1LayoutParams.addRule(RelativeLayout.ABOVE, label2.getId());
  299.  
  300. label1.setLayoutParams(label1LayoutParams);
  301.  
  302.  
  303.  
  304.  
  305. RelativeLayout.LayoutParams label2LayoutParams = new RelativeLayout.LayoutParams(
  306. ViewGroup.LayoutParams.MATCH_PARENT,
  307. ViewGroup.LayoutParams.WRAP_CONTENT
  308. );
  309.  
  310. // ------------------------------------------
  311. // this pins label2 to the parent
  312. // container's bottom, preventing label1
  313. // from forcing label2 off bottom of screen
  314. // ------------------------------------------
  315. label2LayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  316.  
  317. label2.setLayoutParams(label2LayoutParams);
  318. }
  319.  
  320. void addViews() {
  321. getContainer().addView(getLabel1());
  322. getContainer().addView(getLabel2());
  323.  
  324. this.setContentView(getContainer());
  325. }
  326. }
  327.  
  328. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  329. android:layout_width="match_parent"
  330. android:layout_height="match_parent"
  331. android:id="@+id/container">
  332. <TextView
  333. android:id="@+id/label1"
  334. android:text="The quick brown fox jumped over the lazy dog."
  335. android:background="#ccc"
  336. android:gravity="center"
  337. android:textSize="20sp"
  338. android:textAlignment="center"
  339. android:layout_width="match_parent"
  340. android:layout_height="match_parent"
  341. android:layout_above="@id/label2" />
  342.  
  343. <TextView
  344. android:id="@+id/label2"
  345. android:text="Label 2 is a short label compared to label1.It has two lines but take up a fraction of the space."
  346. android:background="@android:color/darker_gray"
  347. android:textSize="20sp"
  348. android:textAlignment="center"
  349. android:layout_width="match_parent"
  350. android:layout_height="wrap_content"
  351. android:layout_alignParentBottom="true"/>
  352. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement