I am new to Android.
I am stuck off in understanding the concept of using weight sum with weighted LinearLayouts. Have skimmed through a number of related questions on StackOverflow but still haven't found the solution.
Scenario
I have an activity layout page with number of components . The components are oriented vertically in the linear layout according to their layout_weights.
Code
<ScrollView fillViewPort="true" scrollBars="true">
<LinearLayout android:weightSum="150">
<!-- Various components present here each assigned layout_weight attribute
Total sum being 150 itself -->
</LinearLayout>
</ScrollView>
Question
My question is that how can I use scroll View and weightSum together such that a total of weightSum=100 displays on one page and for the rest 50 user needs to scroll down.
This is the one idea how it could possible
<LinearLayout weightsum="150" android:orientation="vertical">
<LinearLayout layout_weight="100">
//your LinearLayout
</LinearLayout>
<ScrollView Layout_weight="50">
//your scrollview layout
</ScrollView>
</LinearLayout>
Documentation says that the mission of weightSum is managing spaces below/under all the items of LinearLayout. Moreover, the weight does not purpose for specifying exact size of layout (but only for relative size), so nor for the paging. If you want to scroll Views page-by-page, you can use ViewPager.
Related
I would like to make horizontal swipe scroll with images and text views on it, 3-4 views.
Like tips screen on applications.
But, don't know which component to use, I need something like tabs(3-4 different layouts) but I dont want to show tab menu up. Just full screen, few buttons down, and in middle textbox with tip(which i want to animate later), everything is same in every layout just different image and text.
No code here in question because i stuck on beginning and need few tips what to use or some linked tutorial.
Here is how you can do this.
<ViewFlipper
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pro_flip"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//put your child elements for first page on this layout
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//put your child elements for second page on this layout
</LinearLayout>>
</ViewFlipper>
Content on the first layout will be visible to the user at first, when he swipes the next layout will be loaded.
ViewFlipper should be sufficient for simple content like you mentioned. If you want something more look into ViewPager.
I have been trying for a long time to make Cards similar to appearance that of Google Play Store, ie cards of Different sizes , with images and all inside the card. Any tips on how to proceed.
Basically you just create a layout (RelativeLayout, LinearLayout, etc) as a child of your cardview element and make it look however you want.
For example...
<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardElevation="2dp"
card_view:cardBackgroundColor="#android:color/white"
card_view:cardCornerRadius="2dp">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
//Your desired layout here
</RelativeLayout>
</android.support.v7.widget.CardView>
You can take a look at the MaterialList implementations for some good examples.
I have a problem with a fixed size scrollview that i'm trying to make. I've read many questions that are similar (but not equal) to mine here in StackOverflow and other sites and none of the answers have helped me, so I decided to ask my own question.
Basically, i want a fixed size scrollview with different controls inside. The basic one would be a textview of a dynamically changing size inside it. When I change the text of the textview and it is bigger than the scrollview, the scrollbars flash quickly, as they should, indicating that I can scroll but no matter how many times I swipe my finger, it doesn't scroll. Then I tried swiping with two or three fingers and sometimes (only a counted number of times) it scrolls.
I have tried many different approaches to this, like changing the textview to an edittext with focusable = false so it doesn't give the user chance to edit the text; or putting the textview alone in the scrollview, or wrapping it in linearlayouts, relative layouts etc. and it still doesnt scroll.
Below is the code as it is today. This scrollview is inside a vertical linearlayout along with other controls that I'm not putting 'cause of the length, but if someone needs it, I'll put it. I would appreciate very much if someone can point to my problem or help me solving this.
XML:
<ScrollView
android:id="#+id/scrollFifthHorizontalLineDetails"
android:layout_width="304dp"
android:layout_height="133dp"
android:layout_gravity="center"
android:layout_marginTop="5dp" >
<LinearLayout
android:id="#+id/rrrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txtlblPlaceDetails"
android:layout_width="302dp"
android:layout_height="wrap_content"
android:background="#drawable/placedescriptionbg"
android:text="#string/null_text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</ScrollView>
the line in which I populate the TextView:
((TextView) findViewById(R.id.txtlblPlaceDetails)).setText(mJsonOb.getString("placeDescription"));
I had a similar problem with an Android app I was developing a few months back. I got around the scrolling problem by increasing the layout width for the scroll view. In the editor you can actually drag the RHS of the scroll view to exceed the visible area. I think I set the android:layout_width to about 1024.
In one of my activities I am showing certain information and at the end I have a ListView.
So my layout looks a bit like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="30dip"
>
...
<ListView android:id="#android:id/android:list" android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</LinearLayout>
When I run the application in the emulator I see that the information before the list view is always shown in the screen and there is a vertical scroll for the ListView only.
Is there a way to change this scrolling behaviour ?. What I would like to have is a vertical scroll for all the information in the screen, not only at the level of the ListView.
I tried wrapping the LinearLayout with a ScrollView, with different combinations of the android:layout_height attribute for all the views involved but I did not get the effect that I was looking for. Besides, some people say that it is a pretty bad idea to wrap a ListView with a ScrollView :
Android ScrollView layout problem
Scrolling with Multiple ListViews for Android
Thanks for any other ideas.
I've not tried this, but you might want to look at you tube video:
Google I/O 2010 - The world of ListView
http://www.youtube.com/watch?v=wDBM6wVEO70
Starting at time 27:11, it talks about how to make info above and/or below a ListView scroll with the ListView. It refers to scrolling headers and footers, but it does say you can put anything you want in them.
Little confused with the design in android..suppose i need to position two blocks
as in the figure..what shall i do?..if we use pixels the design looks different in different phones.
Design should be fixed in all phones..but how without using px we can design as above
Use two LinearLayout in your layout xml and set layout_marginLeft,layout_marginTop,layout_marginRight in dip according to the need.
See the following layout, its very similar to the one you want:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:text="Button01"
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
android:layout_marginLeft="30dip"
></Button>
<Button
android:text="Button02"
android:id="#+id/Button02"
android:layout_below="#id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="140dip"
android:layout_marginRight="30dip"
></Button>
</RelativeLayout>
Hope this will solve your issue.
You could generate the layout in Java by getting the screen size and placing two objects (defined in xml or java) into the parent layout, taking into account the ratios.
If dip is unable 2 solve ur problm , surely any of these approaches will work :
1) take a 9patch backgroud with proportionate padding . now put first textview with gravity left|top and second with grvity right|bottom . done
or
2)Take two child of a vertical linearlayot with layout_weight=1 , so will each will take 50% height now to put put textview center vertical . now lets try fix it horizontally.4 each text
take two child textview with layout_weight=1 ,put text center_horizontal .for upper text male second invisible n for lower make first one invisible ......