Swiping the pages with ViewPage - java

I'm trying to fill the page by blocks of linearlayout by data. Also I'm using ViewPager for changing pages. Every page should have its own data blocks, but now I'm getting linearlayouts that doesn't swipes out (blocks stand still when I'm swiping pages) but there is another linearlayout right above the other ones that doesn't constist data but sliding when I swipe pages.
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<android.support.v4.view.ViewPager
android:id="#+id/page"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
<LinearLayout
android:orientation="vertical"
android:id="#+id/page_blocks"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
table_row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/program_frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip">
<TextView
android:id="#+id/StudyName"
/>
<TextView
android:id="#+id/Auditorium"
/>
<TextView
android:id="#+id/StudyKindName"
/>
<TextView
android:id="#+id/LectureTitle"
/>
<ImageView
android:id="#+id/imageView2"
/>
</RelativeLayout>
onCreateView of ViewPage:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.table_row, null);
framesContainer = (LinearLayout) getActivity().findViewById(R.id.page_blocks);
for (int i = 0; i < 16; i += 4) {
Frame frame = new Frame(getActivity());
try {
frame.setStudyName(s.get().get(0).Days().get(i));
frame.setStudyKindName(s.get().get(0).Days().get(i + 1));
frame.setAuditorium(s.get().get(0).Days().get(i + 2));
frame.setLectureTitle(s.get().get(0).Days().get(i + 3));
framesContainer.addView(frame);
} catch (Exception e) {
e.printStackTrace();
}
}
return view;
}
Also pic:
Is there a way to hide the empty block and make all blocks slide after the page when swiping?

Your problem is that you are using RelativeLayouts, and since you are not aligning its children elements(ViewPager and LinearLayout), they are overlapping:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<android.support.v4.view.ViewPager
android:id="#+id/page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<LinearLayout
android:orientation="vertical"
android:id="#+id/page_blocks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/page" >
</LinearLayout>
This line tells the viewpager that its position is going to be at the top of the RelativeLayout:
android:layout_alignParentTop="true"
And this one tells the LinearLayout its position is below the viewpager:
android:layout_below="#id/page"
There are some other properties that can be set --> RelativeLayout
To be honest, I'm not sure what you are trying to do. But maybe you just need to get rid of the RelativeLayout and use LinearLayouts instead.

Related

ExpandableListView Change Indicator State

I have an ExpandableListView setup working very properly and as I wanted but with a minor problem I want the group indicator (the arrow) to expand and collapse when I open or close the group. This function is although partially working but not fully correct.
The problem is that when I expand lets say group1 the indicator of group2 automatically gets invisible (Image at the end of post). and if I continue to expsnd group3 then the indicator of group4 hides. at the end only the terminal groups i.e ending groups have the indicator, the indicators of all other groups are invisible. I tried debugging this very hard but could find any reason as to why this is happening. Maybe you all can take a look!
This is the activity_main.xml (Yes I am Using Android Navigation Drawer Here)
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ExpandableListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:groupIndicator="#null"
android:divider="#F3F3F3"
android:padding="1dp"
android:dividerHeight="1dp"
android:background="#FFFFFF" />
</android.support.v4.widget.DrawerLayout>
drawer_group_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/group_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="24sp"
android:gravity="left"
android:minHeight="30dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textColor="#616161"
android:text="Hello"
android:paddingRight="40dp" />
<ImageView
android:id="#+id/indicator"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingRight="10dp"
android:src="#drawable/ic_action_expand" />
</RelativeLayout>
drawer_list_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/store_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:scaleType="fitXY" />
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:textColor="#616161"
android:textSize="24sp" />
</LinearLayout>
getGroupView from the adapter
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.drawer_group_item, null);
holder.imageView = (ImageView) convertView.findViewById(R.id.indicator);
holder.textView = (TextView) convertView.findViewById(R.id.group_title);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(parentItems.get(groupPosition));
if(groupPosition == 0 || groupPosition == 5){
holder.imageView.setVisibility(View.GONE);
}
if(isExpanded){
holder.imageView.setImageResource(R.drawable.ic_action_collapse);
}
if(!isExpanded){
holder.imageView.setImageResource(isExpanded?R.drawable.ic_action_collapse:R.drawable.ic_action_expand);
}
return convertView;
}
Image: http://imgur.com/JzsVdQz
Image order is right to left (sorry about that)
EDIT: I also want some categories to not expand. like if there is a group which doesnot have subitems I want to hide the indicator for that group. I am using this code currently
if(groupPosition == 0 || groupPosition == 5){
holder.imageView.setVisibility(View.GONE);
}
but how do i hide the indicator in the statelist xml and setIndicatorBounds method (as stated by user3664308)
You should instead create a drawable with different states for an expanded and collapsed group like:
drawable/group_indicator.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_expanded="true"
android:drawable="#drawable/ic_action_expand" />
<item
android:drawable="#drawable/ic_action_collapse" />
</selector>
And then set the indicator:
mExpList.setIndicator(R.drawable.group_indicator.xml);
Then adjust the indicators position by setting its bounds:
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
mListView.setIndicatorBounds(myLeft, myRight);
} else {
mListView.setIndicatorBoundsRelative(myLeft, myRight);
}

Get only top part of camera

I am stuck at this Issue since couple of days. What I want is only part of the camera to be shown on screen. This is what I want:
This is what I have done:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="200dp">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="160dp"
android:scrollbars="none"
android:fillViewport="true"
>
<LinearLayout
android:id="#+id/linearLayoutBeautyContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/surfaceViewBeautyCamera"/>
</LinearLayout>
</ScrollView>
<TextView
android:id="#+id/scanText"
android:text="Scanning..."
android:layout_height="wrap_content"
android:layout_width="match_parent">
</TextView>
</LinearLayout>
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final LayoutInflater inflator = getLayoutInflater();
final LinearLayout inflate = (LinearLayout) inflator.inflate(R.layout.main, null);
final SurfaceView surfaceView = (SurfaceView) inflate.findViewById(R.id.surfaceViewBeautyCamera);
final SurfaceHolder holder = surfaceView.getHolder();
WindowManager mW = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
int screenWidth = mW.getDefaultDisplay().getWidth();
int screenHeight = mW.getDefaultDisplay().getHeight();
final ViewGroup.LayoutParams slayout = surfaceView.getLayoutParams();
slayout.width = screenWidth;
slayout.height = screenHeight;
surfaceView.requestLayout();
final ScrollView beautyContent = (ScrollView) inflate.findViewById(R.id.scrollView);
holder.addCallback(new SurfaceHolder.Callback() {
#Override
public void surfaceCreated(SurfaceHolder holder) {
try {
camera = getCamera();
camera.setPreviewDisplay(holder);
camera.setDisplayOrientation(90);
camera.startPreview();
} catch (IOException e) {
Log.i("Lucy", e.getMessage());
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
});
addContentView(inflate, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}
public Camera getCamera() {
try {
final Camera open = Camera.open();
return open;
} catch (Exception ex) {
Log.i("Lucy", ex.getMessage());
return null;
}
}
When i do this I get:
The Idea is to set the size of SurfaceView as full screen but reduce the size of scroll view. But what I want is the first Image. What am I doing wrong?
Observations:
When I scroll the view up completely. Go back to Home Screen and open the app again. i get the first image. But if I scroll again and go back to main to come back, i get the second Image.
Any other strategy?
PS:
1. Having other view on top of camera is also option, but I cannot use it for lengthy reasons
The problem is the height settings for your elements:
Your root element should be a relative layout, you can then set the fixed height of the camera view and set the textview with the text to height match parent and layout_below the scroll view.
try this layout.But don't understand why use scrollView.
I post 2 layout
First one where surface mean camera face is 160dp
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayoutBeautyContent"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:orientation="vertical" >
<SurfaceView
android:id="#+id/surfaceViewBeautyCamera"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<TextView
android:id="#+id/scanText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_below="#id/linearLayoutBeautyContent"
android:background="#000000"
android:text="Scanning..." >
</TextView>
</RelativeLayout>
2nd one is, camera will capture fullscreen size picture but u can see only 160 window at time of capture
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayoutBeautyContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<SurfaceView
android:id="#+id/surfaceViewBeautyCamera"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<TextView
android:id="#+id/scanText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_marginTop="160dp"
android:background="#000000"
android:text="Scanning..." >
</TextView>
</RelativeLayout>
I dont know why you put surfaceView in the scrollView But I put up with your layout file and its works for me as you show in expected snapshot result .
Edits:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/linearLayoutBeautyContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<SurfaceView
android:id="#+id/surfaceViewBeautyCamera"
android:layout_width="match_parent"
android:layout_height="160dp" />
<TextView
android:id="#+id/scanText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Scanning..." >
</TextView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</LinearLayout>

adding view to ViewFlipper causes java.lang.StackOverflowError

I want to have a dialog with buttons
whenever i click on a specific button, I want the dialog to "flip" and show another layout. A click on another button will return to the original dialog's view.
I try to use ViewFlipper as follows:
xmls:
send_feedback_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/feedback" />
</LinearLayout>
...
social_actions_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_activity_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent" >
<ViewFlipper
android:id="#+id/viewFlipper"
android:layout_width="300dp"
android:layout_height="407dp"/>
<RelativeLayout
android:id="#+id/main_activity_card_face"
android:layout_width="300dp"
android:layout_height="407dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#android:color/white"
android:clickable="true"
android:onClick="onCardClick"
android:padding="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
...
code:
final ViewFlipper viewFlipper = (ViewFlipper) mDialog
.findViewById(R.id.viewFlipper);
View feedbackview = View.inflate(mContext,
R.layout.send_feedback_dialog, viewFlipper);
// ((ViewGroup)
// feedbackview.getParent()).removeView(feedbackview);
// viewFlipper.addView(feedbackview);
// View socialActions = View.inflate(mContext,
// R.layout.social_actions_dialog, viewFlipper);
// ((ViewGroup) socialActions.getParent())
// .removeView(socialActions);
// viewFlipper.addView(socialActions);
private void flipDialog(ViewFlipper viewFlipper,
boolean isSocialActionsShown, AlphaAnimation alphaIn,
AlphaAnimation alphaOut) {
if (isSocialActionsShown) {
isSocialActionsShown = false;
viewFlipper.setInAnimation(alphaIn);
viewFlipper.setOutAnimation(alphaOut);
// Show the next Screen
viewFlipper.showNext();
} else {
isSocialActionsShown = true;
viewFlipper.setInAnimation(alphaIn);
viewFlipper.setOutAnimation(alphaOut);
viewFlipper.showPrevious();
}
}
I used to get java.lang.StackOverflowError and then i have commented some rows and now the flip is executed but nothing changes.
how can i make it properly work?
what is the right way to organize the dialog layout in different files?
i have tried to create the dialog in a different file but it requires many things and maybe it's better to use it as an inner class

Height MapFragment Layout not work

I'm build an app that contain two tabhost (top and botton) and in one tab, I want to put a Google Map through the Google API. All works well but the map does not display correctly. You can see better in this picture:
My code is:
fragment_mapa.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
MapaFragment.java
public class MapaFragment extends Fragment {
public MapaFragment(){}
public GoogleMap mapa;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_mapa, container, false);
if (container != null) {
container.removeAllViews();
}
GoogleMap map = ((SupportMapFragment) getActivity().getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
((MainActivity) getActivity()).setBar();
//Asigno el nombre de la vista e integro tabhost-sliding
((MainActivity) getActivity()).setTitle("Mapa");
((MainActivity) getActivity()).integrationMenu();
return rootView;
}
public void onDestroyView() {
super.onDestroyView();
Log.d("DESTROY", "onDestroyView");
Fragment f = getActivity()
.getSupportFragmentManager().findFragmentById(R.id.map);
if (f != null) {
getActivity().getSupportFragmentManager()
.beginTransaction().remove(f).commit();
}
}
}
And my activity_main.xml that contain the two tabhost and a framelayout that call the fragments:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Estructura de los dos tabhost -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- TABHOST SUPERIOR -->
<RelativeLayout
android:id="#+id/l1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="right"
android:layout_above="#+id/l2"
android:layout_alignParentTop="true">
<android.support.v4.app.FragmentTabHost
android:id="#+id/tabhost_sup"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_weight="0"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0"/>
</ScrollView>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</RelativeLayout>
<!-- TABHOST INFERIOR -->
<RelativeLayout
android:id="#+id/l2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_weight="1"
android:gravity="right"
android:layout_alignParentBottom="true"
android:background="#android:color/background_light" >
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/RelativeLayout1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="0dp"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</RelativeLayout>
</RelativeLayout>
<!-- Listview to display slider menu -->
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector"
android:background="#color/list_background"/>
<ListView
android:id="#+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector"
android:background="#color/list_background"/>
</android.support.v4.widget.DrawerLayout>
Removing scrollview is not convinient solution.Instead of it try android:FillViewPort="True" for Scrollview in your layout solve your problem for all screen where you may require scroll for your activity content.Hope this helps you!!
SOLUTION (by Hardik):
Remove the scrollview in my activity_main.xml and it works well.
Use hierarchiviewer of android tools to check layout values.
For the future:
If you have a ScrollView then elements must specify their height (width for horizontal scroll view) otherwise what height should they have, infinite?
I also had an issue where the exact thing happened when placing the map fragment inside a Relative Layout that had height = Wrap_Content, with minimum height.
Setting a constant height resolved the issue, same idea.
came across this same issue but my map fragment is inside a scrollview and it needs to have a scrollview since there are also other views aside from the map. if it only contains the map, then yes scrollview is not needed.

Dynamically adding TextView to ScrollView on Android

I try to make a ScrollView to act like a ListView. So every row will be a TextView added dynamically. but the program crashes. I have a ScrollView inside a LinearLayout. What i do wrong? Thanks.
Here is my code
scroll = (ScrollView)findViewById(R.id.scrollView1);
layout = (LinearLayout) findViewById(R.id.LinearLayout1);
layout.setBackgroundColor(Color.TRANSPARENT);
TextView[] tx = new TextView[10];
for (int i = 0; i < 10; i++) {
tx[i] = new TextView(HelloWorldActivity.this);
tx[i].setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
tx[i].setText("This is the textviewNo" + i);
layout.addView(tx[i]);
}
scroll.addView(layout);
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/timeflag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="50sp"
android:gravity="center"/>
<Button
android:id="#+id/pause"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/timeflag"
android:layout_marginTop="37dp"
android:text="Start" />
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/pause"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ScrollView>
</LinearLayout>
</RelativeLayout>
A scrollView Can only have one child. If you try to add more than 1 child to the scroll view then it will crash. You should have the LinearLayout inside of the scrollview and then dynamically add textViews to the linear layout.
You are trying to add LinearLayout1 as its own child's child (being your own grandfather, is a confusing notion).
Change you XML around like this:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/pause"
>
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
You cannot add views to a scrollview. You can only add them to a viewgroup, like linear or relativelayout.
It is not exactly clear what you are trying to achieve, but what is wrong with using a listview for this? You could set a max height on the listview. Or you could try wdziemia's suggestion

Categories

Resources