Inflating RelativeLayout View into horizontal scroll view deletes layout settings - android

Sorry for the long question..
I have Relativelayout of elements I am adding dynamically into Linearlayout of Horizontalscrollview.
When I see the layout the preview seems great, but when I am adding it programmatically it ruins the view.. the Text moved to another locations on the layout, and the padding is ignored..
This is the Relativelayout element deal_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="310dp"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
android:id="#+id/deal_layout"
>
<ImageView
android:layout_width="310dp"
android:layout_height="130dp"
android:src="#drawable/deal_square"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:contentDescription="deals background" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingTop="25dp"
android:id="#+id/from_to_deals_txt"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="from "
android:textAppearance="#style/from_to_deals"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Source"
android:textAppearance="#style/source_deals"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" to "
android:textAppearance="#style/from_to_deals"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="destination"
android:textAppearance="#style/dst_deals"
android:layout_below="#id/from_to_deals_txt"
android:layout_alignRight="#id/from_to_deals_txt"
android:paddingTop="10dp"
android:id="#+id/dst_deals_txt"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1099 X"
android:textAppearance="#style/price_deals"
android:layout_below="#id/dst_deals_txt"
android:layout_alignRight="#id/from_to_deals_txt"
android:layout_alignEnd="#id/from_to_deals_txt"
android:paddingTop="10dp"
android:id="#+id/price_deal_txt"
/>
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/ic_launcher"
android:background="#000000"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
/>
</RelativeLayout>
This is the Horizontal scroll view:
<?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="fill_parent"
android:background="#drawable/bg"
android:padding="10dp">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dealsView"
android:paddingTop="10dp"
>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
I am adding the Relativelayout elements with this java function:
LinearLayout dealsView;
dealsView = (LinearLayout)findViewById(R.id.dealsView);
for(int i=0;i<5;i++)
{
LayoutInflater mInflater ;
mInflater = LayoutInflater.from(this);
View cur_deal = mInflater.inflate(R.layout.deal_layout, null);
dealsView.addView(cur_deal);
}
In the preview it looks like this:
On the application it looks like this:
Does anyone has idea what am I doing wrong?
When I am adding the elements with copy paste to the linearlayout it seems great, and the margin is works fine, only from the code it not works..
Thanks!

Instead of passing null to the inflater, pass the Views intended parent (dealsView) so that the LayoutParams from the root can be used to inflate.
View cur_deal = mInflater.inflate(R.layout.deal_layout, dealsView, false);
I believe the issue is caused by all of your Views using width="wrap_content" but without the inflater knowing the root it cannot properly inflate that value.

Related

Android move view below another programatically

I have three views that are part of a list view cell.
<?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="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/postArea"
android:layout_below="#+id/date"
android:layout_alignLeft="#+id/date"
android:layout_alignStart="#+id/date"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="5dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/date"
android:layout_alignLeft="#+id/date"
android:layout_alignStart="#+id/date"
android:id="#+id/shareView">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/shareView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/commentsView">
</RelativeLayout>
</RelativeLayout>
In some cells "shareView" is set to shareView.setVisibility(View.GONE);
When this is the case I need to change commentsView so that it is below postArea instead.
Its there a way to do this within my getView method.
When you set your shareView's visibility to View.GONE, you should change the layout_below rule for your commentsView. Like this:
RelativeLayout commentsView = (RelativeLayout)findViewById(R.id.commentsView);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)commentsView.getLayoutParams();
params.addRule(RelativeLayout.BELOW, R.id.postArea);
commentsView.requestLayout();

Adding LinearLayout xml in a ScrollView

I have a xml with a ScrollView and a LinearLayout as a child of ScrollView.
<?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" >
<ViewStub
android:id="#+id/social_empty_stub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:inflatedId="#+id/social_empty_stub_inflted"
android:layout="#layout/empty_screen"
android:visibility="gone" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/activity_stream"
android:background="#DCDCDCDC"
android:fadingEdge="none" >
<LinearLayout
android:id="#+id/activity_stream_wrap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
and I have another xml with a LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<!-- List Item on activity stream -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout_Activity_Streams"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp" >
<!-- Avatar -->
<com.example.bb.ShaderImageView
android:id="#+id/imageView_Avatar"
android:layout_width="#dimen/social_avatar_size"
android:layout_height="#dimen/social_avatar_size"
android:layout_marginLeft="5dp"
android:scaleType="fitXY" />
<!-- Content -->
<LinearLayout
android:id="#+id/relativeLayout_Content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="5dp"
android:background="#drawable/news_browser_background_shape"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="#+id/textView_Name"
style="#style/textview_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:maxLines="5"
android:textStyle="bold" />
<TextView
android:id="#+id/textView_Message"
style="#style/textview_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="3dip"
android:maxLines="5" />
<TextView
android:id="#+id/textview_temp_message"
style="#style/textview_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="3dip"
android:maxLines="5"
android:visibility="gone" />
<ViewStub
android:id="#+id/attached_image_stub_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="2dp"
android:inflatedId="#+id/attached_image_stub_inflate"
android:layout="#layout/activity_image_display_layout"
android:padding="5dp"
android:visibility="gone" />
<TextView
android:id="#+id/activity_comment_view"
style="#style/textview_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="3dip"
android:maxLines="5"
android:visibility="gone" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:gravity="center_vertical">
<ImageView
android:id="#+id/activity_image_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/ImageDesc"
android:layout_marginLeft="5dp"
android:padding="2dp"
android:scaleType="fitXY" />
<!-- Time text view -->
<TextView
android:id="#+id/textView_Time"
style="#style/textview_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/activity_image_type"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:layout_marginRight="3dp" />
<!-- Comment button -->
<Button
android:id="#+id/button_Comment"
style="#style/textview_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/social_activity_browser_comment_button_shape"
android:gravity="center_vertical"
android:padding="2dp" />
<!-- Like button -->
<Button
android:id="#+id/button_Like"
style="#style/textview_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/button_Comment"
android:background="#drawable/social_activity_browser_like_button_shape"
android:gravity="center_vertical"
android:padding="2dp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Now I want to add the LinearLayout in second xml programmatically in ScrollView of first xml. I am using following code
setContentView(R.layout.activitybrowserview);
View view = LayoutInflater.from(context).inflate(R.layout.activitybrowserviewcell, null);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.RelativeLayout_Activity_Streams);
ScrollView sv = (ScrollView) findViewById(R.id.activity_stream);
sv.addView(ll);
I get following error, how can I avoid that. I don't understand the error.
IllegalStateException "Scrollview can host only one direct child"
Scrollview can host only one direct child,the scrollvie has direct child yet(android:id="#+id/activity_stream_wrap"),u should add view with this one.
setContentView(R.layout.activitybrowserview);
View view = LayoutInflater.from(context).inflate(R.layout.activitybrowserviewcell, null);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.RelativeLayout_Activity_Streams);
LinearLayout parentLl = (LinearLayout ) findViewById(R.id.activity_stream_wrap);
parentLl .addView(ll);
In your first XML file you have
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/activity_stream"
android:background="#DCDCDCDC"
android:fadingEdge="none" >
<LinearLayout
android:id="#+id/activity_stream_wrap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
If you remove the <LinearLayout> here, then you can add another LinearLayout instead. You can either remove it directly from the XML file or remove it programatically.
Just add a Linear Layout as a container to your current LinearLayout and the LinearLayout that you want to add pragmatically. I think this should solve your problem. ScrolView Can contain only one child as the exception says the same.
<ScrolView>
<LinearLayout> this will be the container
<linearlayout> the one that is currently in the first xml file
</LinearLayout>
</LinearLayout>
</ScrolView>
Hope this will help.
setContentView(R.layout.activitybrowserview);
View view = LayoutInflater.from(context).inflate(R.layout.activitybrowserviewcell, null);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.RelativeLayout_Activity_Streams);
ScrollView sv = (ScrollView) findViewById(R.id.activity_stream);
sv.removeAllViews();
sv.addView(ll);

Add multiple children layouts from XML file to another layout

My layout is based on what Android Studio creates - blank with an action bar. This is the default code to inflate my fragment_list.xml into activity_stats.xml (I only have one Java file)
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_list, container, false);
return rootView;
}
Activity_stats is unaltered, just like Android Studio generated it. This is fragment_list.xml
<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="com.company.dummyname.stats$PlaceholderFragment" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipToPadding="false"
android:paddingTop="#dimen/network_margin_vertical"
android:paddingLeft="#dimen/network_margin_horizontal"
android:paddingRight="#dimen/network_margin_vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/networkContainer"/>
</ScrollView>
</RelativeLayout>
I want to add multiple children to networkContainer. The children should be layouts from network.xml, which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.company.dummyname.stats$PlaceholderFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
grid:columnCount="2" >
<ImageView
android:layout_width="88dp"
android:layout_height="70dp"
android:background="#fff8cdac"
grid:layout_row="0"
grid:layout_column="0"
grid:layout_rowSpan="2"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
grid:layout_row="0"
grid:layout_column="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9999.99"
android:id="#+id/totalToday"
android:textSize="32sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" today"
android:textSize="32sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="46dp"
android:paddingLeft="8dp"
grid:layout_row="1"
grid:layout_column="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9999.99"
android:id="#+id/totalYesterday"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" yesterday"
android:textSize="24sp" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
grid:layout_row="2"
grid:layout_columnSpan="2">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
style="#style/StatsCell" />
<TextView
style="#style/StatsCell"
android:text="Hits" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
style="#style/StatsCell"
android:text="Today"
android:layout_height="match_parent" />
<TextView
style="#style/StatsCell"
android:id="#+id/todayHits"
android:text="9999" />
</TableRow>
</TableLayout>
</android.support.v7.widget.GridLayout>
There will be more data and one more row, but I removed them to simplify the question. The goal is to have many instances of network.xml with different data. How do I insert them and alter the data inside? I did research on Google, but without success. Please ignore the hardcoded strings and dimensions, I'll fix that.
EDIT: I need to add the children programmatically, not in XML, because the number of network.xml instances will vary depending on user settings.
IN XML
To Include multiple layouts you should use include element in the parent layout to referring to child layouts
IN CODE (PROGRAMATICALLY)
In the onCreateView function where you get the root View try to get the container layout like this
LinearLayout layout = (LinearLayout) rootView.findViewById(R.id.networkContainer);
and then in that linear layout create and add the instances of the other views you want to add like this
to get the View for the child Layout use LayoutInflator
layout.addView(newView);
and finally return the parent View

Add a view that occupies the whole screen

I have a relative layout with transparent background and a some views arranged in the middle, i inflate this layout and add it to the main layout with addView(), the inflated view just adds the middle elements in the corner to the parent layout, how can i make the added view occupy all the screen (tried fill_parent but it just gets ignored)
This is the view i inflate
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent" >
<RelativeLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#color/info_bar_bg_color" >
<ImageView
android:id="#+id/channel_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/channel_pic"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/title_color"
android:textSize="#dimen/title_text_size" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/date_color"
android:textSize="#dimen/date_text_size" />
<TextView
android:id="#+id/hourStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/date"
android:textColor="#color/title_color"
android:textSize="#dimen/title_text_size" />
<TextView
android:id="#+id/hourEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/hourStart"
android:textColor="#color/title_color"
android:textSize="#dimen/title_text_size" />
<ImageView
android:id="#+id/share_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/epgshare_0" />
<ImageView
android:id="#+id/bell_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/share_pic"
android:src="#drawable/epgsharebell_0" />
</RelativeLayout>
</RelativeLayout>
and this is the main layout i add the view to
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ic_launcher"
tools:context=".MainActivity" >
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="openInfoBar"
android:text="Open InfoBar" />
</RelativeLayout>
i inflate this layout and add it to the main layout with addView(),
the inflated view just adds the middle elements in the corner to the
parent layout,
That is happening(most likely) because you don't setup the proper LayoutParams for the inflated layout view. You probably use something like this:
View v = inflater.inflate(R.layout.to_fill_parent, null);
which combined with the simple addView(v) method will make the view behave like you see.
The correct way would be:
View v = inflater.inflate(R.layout.to_fill_parent, (ViewGroup)findViewById(R.id.layout), false);
//add the view with addView
Change the :
<RelativeLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#color/info_bar_bg_color" >
such as :
android:layout_width="500dp"
android:layout_height="600dp"
You must try another numbers not the 500 and 600 ,,,, when you have the best size save it ^_^

adding elements to scrollview using java when there is more then 1 child

I am trying to add elements to my scrollview,
this scroll view has a vertical linear layout inside of it.
(i added another linear layout - horizontl, inside that will manage 2 textviews and an image according to the attributes i assigned them),
i am trying to add elements of this inner layout to my scroll view (id=insideLineLayout)
(each element added to scrollview will contain these 2 texts and an image)
because of the fact scrollview can only have 1 child i am unable to do this.
would appreciate some help, nothing seems to be working here.
Thanks.
my current xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/searchScreenOuterLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="#+id/catagoryselectedText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:text="selected catagory"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="12dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/searchText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp" />
<ImageButton
android:id="#+id/searchButton"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/search_icon" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/radiusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:paddingTop="5dp"
android:text="Search Radius"
android:textAppearance="?android:attr/textAppearanceMedium" />
<SeekBar
android:id="#+id/radiusBar"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp" />
</LinearLayout>
<ScrollView
android:id="#+id/searchScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/searchScrollViewLinear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="10dp" >
<LinearLayout
android:id="#+id/insideLineLayout"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:weightSum="100"
>
<TextView
android:id="#+id/linesPrice"
android:layout_weight="20"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="tmp1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/linesInfo"
android:layout_weight="60"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="tmp2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageInfo"
android:layout_width="40dp"
android:layout_height="match_parent"
android:background="#drawable/tv_icon" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Consider how long your list can get as ListView has been optimized in many ways which a regular scroll view is not. If you have too many elements you might start get out of memory exceptions.
In order to dynamically add views to a ScrollView you first need to get the container view inside the ScrollView (most likely a LinearLayout), then you simply do following for each view you add:
View view = inflater.inflate(R.layout.view_to_add, container, false); // this is used if you create from xml, if you make it in code you'd use the regular constructor.
// update the view content (view.findViewById(); etc.)
container.addView(view);

Categories

Resources