tag:blogger.com,1999:blog-865923359735383241.post7565099549361126691..comments2023-10-29T07:27:09.012-06:00Comments on Ccna final exam - java, php, javascript, ios, cshap all in one: How to create two views in Android that use 50% height each, unless one is smaller?Unknownnoreply@blogger.comBlogger6125tag:blogger.com,1999:blog-865923359735383241.post-90757817527539182702012-04-10T03:49:45.101-06:002012-04-10T03:49:45.101-06:00OK as I see its something like u are reserving at ...OK as I see its something like u are reserving at max half of ur screen to the TextView and if its more it has to scroll. I have a solution but for that you will have to fix the max no.l of lines for TextView, calculating which can be a pain :P but have a solution never the less.<br /><br />main.xml file<br /><br /><?xml version="1.0" encoding="utf-8"?><br /><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:layout_width="fill_parent"<br /> android:layout_height="fill_parent"<br /> ><br /><TextView <br /> android:layout_width="fill_parent" <br /> android:layout_height="wrap_content" <br /> android:scrollbars="vertical"<br /> android:maxLines="5"<br /> android:id="@+id/tv1"<br /> android:text="wsdvsv sjdgv jsdvn ksdjbn skjdb ksdnbk snbk snbjksn fkbj sfkbjn dfkjbndkjfbn kdjfnb kjdfnbkjdnfbk ndf bjkndf bndfjbn dfkbn jdfnbjdfnbjdfn bjdf nbkjdnf bkjdfnb kjdnfbkjdfn bkjndfbjndfjbndkjfbn dkfjbn kdjfnb kjdfnbkjdfnbjkd nfkjbndf"<br /> /><br /> <TextView <br /> android:layout_width="fill_parent" <br /> android:layout_below="@id/tv1"<br /> android:layout_height="wrap_content" <br /> android:scrollbars="vertical"<br /> android:maxLines="5"<br /> android:text="Does it work ???"<br /> /><br /></RelativeLayout><br /><br /><br />Java file:<br /><br />package com.android;<br /><br />import android.app.Activity;<br />import android.os.Bundle;<br />import android.text.method.ScrollingMovementMethod;<br />import android.widget.TextView;<br /><br />public class TestActivity extends Activity {<br /> /** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /> TextView tv = (TextView) findViewById(R.id.tv1);<br /> tv.setMovementMethod(new ScrollingMovementMethod());<br /> }<br />}<br /><br /><br />If the text is say only in 2 lines "Does it work?" will shift up automatically. But the only problem i see here is the max lines to 5 is you can an max value for u i guess this might work well :)<br /><br />BR,<br />J<br /><br />P.S. I haven't answered many questions before so i m not sure how to attach files :(Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-46773867937724745122012-04-10T03:49:44.377-06:002012-04-10T03:49:44.377-06:00I am sorry if you find this trivial.
But I am sugg...I am sorry if you find this trivial.<br />But I am suggesting it in case it did not strike you. <br />How about using relative layout and keeping the textview always on top of the map.<br />Make the gravity of the textview top, its width match_parent, its height wrap_content and its weight 1(same as that of thee map). That way your textview will change according to the size of the text, while not going above 50% because of the weight. As for the map, the user can pull the map down to see the hidden part under textview. It'll be as if there is no map under the textview(you know, unless you want to make the textview background transparent which i think would look cool :) ). I do not know about the map view. But I am assuming it'll be something like google maps on iphone, like you can vary size using multi-touch and scroll using single.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-64989896702976001952012-04-10T03:49:43.573-06:002012-04-10T03:49:43.573-06:00i think you have to set mapviews height as fill pa...i think you have to set mapviews height as fill parent and set textviews height as wrap contetn and than for scrolling you have toset vertical scrool true for text view and as you nedded not more than 50% space textview you can set maxheight property of textview.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-7473594596793426892012-04-10T03:49:42.634-06:002012-04-10T03:49:42.634-06:00I haven't tested this, but I'd try setting...I haven't tested this, but I'd try setting your ScrollView to have android:layout_weight="1" and your MapView to have android:layout_weight="0" and a android:minHeight="240dp". The hope is that minHeight will have precedence over layout_weight.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-49548088461629005412012-04-10T03:49:41.599-06:002012-04-10T03:49:41.599-06:00You can do it by putting everything into LinearLay...You can do it by putting everything into LinearLayout and changing following parameters:<br /><br /><br />the sum of weights for LienarLayout<br />weights for childrenUserhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-89714948825303661442012-04-10T03:49:40.518-06:002012-04-10T03:49:40.518-06:00Did you try to measure your screen hight at run ti...Did you try to measure your screen hight at run time: <br /><br />Display display = ((WindowManager) <br /> getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); <br />int width = display.getHeight();<br /><br /><br />Then, set your top view max_height to width*0.5 and min_height to width*0.2. Your top view has to be control (like TextView) that has min_height and max_height properties. Also, set layout_weight to 0 or leave it empty.<br />On your bottom view set layout weight to 1.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.com