I am trying to create a custom dialog configured with a couple of textviews, an edittext, scrollview and a "Ok" button. For some reasons, I have not been able to correctly align the "Ok" button in the dialog.
My snipped code for the creation of dialog is as below:
mLineupDialog=new Dialog(context,R.style.CustomDialogTheme);
mLineupDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
View view = LayoutInflater.from(context).inflate(R.layout.custom_dialog, null, false);
rg = (RadioGroup) view.findViewById(R.id.radiogroup);
RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
for (int i = 0; i < lobjs.length; i++){
rb = new RadioButton(context);
rb.setText(lobjs[i].carrierName);
rb.setId(i);
// rb.setTextColor
rg.addView(rb, layoutParams);
}
zipEntry.setText(mZipCode);
mPrefs.edit().putString(sharedZipEntry, mZipCode).commit();
}
mLineupDialog.setContentView(view);
Button Ok =(Button)view.findViewById(R.id.lineupdialogButton);
My Layout file is as below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linlayoutBase"
android:layout_width="#dimen/favorite_dialog_width"
android:layout_height="match_parent"
android:background="#drawable/add_remove_to_favs_question_bottom_bubble"
android:focusableInTouchMode="false"
android:orientation="vertical" >
<TextView
android:id="#+id/lineup_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/favorite_dialog_text_margin_left"
android:layout_marginTop="#dimen/favorite_dialog_text_margin_top"
android:text="#string/sel_lineup"
android:textColor="#color/white_font"
android:textSize="#dimen/fav_alert_text_size"
android:typeface="sans" >
</TextView>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/zipcode_prompt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/favorite_dialog_text_margin_left"
android:text="#string/sel_zipcode"
android:textColor="#color/white_font"
android:textSize="#dimen/fav_alert_text_size"
android:typeface="sans" >
</TextView>
<EditText
android:id="#+id/zipEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#color/white_font"
android:textSize="#dimen/fav_alert_text_size"
android:typeface="sans" >
</EditText>
</LinearLayout>
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/linearMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/favorite_dialog_text_margin_left" >
<RadioGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/favorite_dialog_text_margin_left"
android:orientation="vertical"
android:textColor="#color/white_font"
android:textSize="#dimen/fav_alert_text_size"
android:typeface="sans" >
</RadioGroup>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/lineupdialogButton"
android:layout_width="#dimen/favorite_dialog_button_width"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:gravity="center_horizontal"
android:text="#string/favorite_dialog_button_ok_text"
android:textColor="#xml/info_panel_button_text_watch_selector"
android:textSize="#dimen/favorite_dialog_button_text_size"
android:textStyle="bold"
android:typeface="sans" >
<!-- android:layout_weight="1" -->
</Button>
</LinearLayout>
The problem is the OK button is just getting laid out partially out of the bottom border of dialog box. . Any suggestion to fix this would be greatly appreciated! Thanks!!
Image of the custom dialog attached
Related
XAMARIN ANDROID DYNAMIC CLICK: I want the spinner, edit text and positive button to be placed side by side such that when the button is clicked by any user, it regenrates the same content (spinner, edittext and a negative button) and for every click on the positive button the same thing happens while for every click on the negative button, the content where the negative button is will be removed.
<?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/layoutTeste"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Spinner
android:id="#+id/spn"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#id/et" />
<EditText
android:id="#+id/et"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:hint="Enter a Value"
android:layout_gravity="center"
android:layout_marginLeft="70dp" />
<Button
android:id="#+id/btnDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnDisplay"
android:layout_alignParentRight="true"
android:layout_alignBaseline="#id/et" />
</RelativeLayout>
Dynamically you can create view in xamarin android programmatically for your need.
For Example
LinearLayout LL = FindViewById<LinearLayout(Resource.Id.Linear_MS); //root layout
var param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
param.SetMargins(20, 20, 20, 10);
var et = new EditText(this);
LL.AddView(et, param);
In Xml side by side design use this.
<?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/layoutTeste"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Spinner
android:id="#+id/spn"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_alignTop="#id/et" />
<EditText
android:id="#+id/et"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="Enter a Value"
android:layout_gravity="center"
android:layout_weight="1"
/>
<Button
android:id="#+id/btnDisplay"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/btnDisplay"
android:layout_weight="1"
/>
</LinearLayout>
</RelativeLayout>
I've a problem with dialog display dimension. With following code i make my custom dialog with ScrollView inside, but when it shown, ScrollView fit dialog dimension, but the inside linear layout has some controls out of scrollable area.
I can't understand why and how to resolve.
Into phone with little display it's a problem because some controls are unreachable.
Dialog creation:
AlertDialog.Builder alert = new AlertDialog.Builder(DataMainPage.this);
startNewTestSessionDialog = new StartTestDialog(DataMainPage.this);
alert.setView(startNewTestSessionDialog);
alert.setPositiveButton("Start", new DialogInterface.OnClickListener() {<...>});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {<..>});
Dialog d = alert.create();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
d.show();
d.getWindow().setAttributes(lp);
Dialog view xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sample="http://schemas.android.com/apk/res/ips.tecnos.saildata"
android:id="#+id/startTest_dialogView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="65dp"
android:fillViewport="true" >
<LinearLayout
android:id="#+id/startTest_viewContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clipToPadding="false"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginBottom="5dp" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:layout_marginRight="7dp"
android:gravity="right|center_vertical"
android:text="#string/testStart_disableWind"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/startTest_disableWind"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_marginTop="10dp"
android:text="#string/testStart_boatType"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:weightSum="3"
android:layout_marginBottom="5dp" >
<Spinner
android:id="#+id/startTest_boatSelect"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:layout_weight="2"
android:gravity="center|right" />
<Button
android:id="#+id/startTest_modifyBoatPolar"
android:layout_width="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/testStart_modboatPolar" />
</LinearLayout>
<...other controls with same logic...>
</LinearLayout>
</ScrollView>
Screenshoot (Nexus5): ScrollView is at its end, and as you can see button and hidden spinner is out of scrollView border.
Screnshoot
With some casual changes i found solution!
The problem was property of ScrollView:
android:layout_gravity="center"
removing it, the layout is right positioned.
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);
I have an activity with dialog theme. Its layout has 3 parts
HEADER
BODY (HAS ListView)
OK BUTTON
This has to be the structure of my layout always. If I use following layout xml:
<?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"
android:layout_margin="10dip" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/iv_av_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginTop="2dip"
android:paddingLeft="6dip"
android:src="#drawable/tablet_ic_logo" />
<RelativeLayout
android:id="#+id/rl_av_found"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/iv_av_logo"
android:layout_marginBottom="5dip"
android:paddingLeft="16dip" >
<TextView
android:id="#+id/tv_av_found"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/orange"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_av_recommendation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_av_found"
android:layout_marginBottom="8dip"
android:textColor="#color/white"
android:textSize="13dp"
android:visibility="gone" />
</RelativeLayout>
<LinearLayout
android:id="#+id/ll_av_body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/rl_av_found"
android:background="#drawable/tablet_dialog_glow" >
<ListView
android:id="#+id/lv_av_threats_found"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#drawable/tablet_dialog_separator" >
</ListView>
</LinearLayout>
<RelativeLayout
android:id="#+id/rl_button_bar"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:layout_below="#id/ll_av_body" >
<Button
android:id="#+id/btn_av_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:onClick="onClick"
android:text="#string/btn_ok" />
<ImageView
android:id="#+id/iv_separator"
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentTop="true"
android:background="#drawable/tablet_dialog_footer" />
</RelativeLayout>
</RelativeLayout>
It gives me what I want. But if the list grows and I have say 100 items, OK button goes out of the picture.
And if I use this layout:
<?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"
android:layout_margin="10dip" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/iv_av_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginTop="2dip"
android:paddingLeft="6dip"
android:src="#drawable/tablet_ic_logo" />
<RelativeLayout
android:id="#+id/rl_av_found"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/iv_av_logo"
android:layout_marginBottom="5dip"
android:paddingLeft="16dip" >
<TextView
android:id="#+id/tv_av_found"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/orange"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_av_recommendation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_av_found"
android:layout_marginBottom="8dip"
android:textColor="#color/white"
android:textSize="13dp"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_button_bar"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/btn_av_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:onClick="onClick"
android:text="#string/btn_ok" />
<ImageView
android:id="#+id/iv_separator"
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentTop="true"
android:background="#drawable/tablet_dialog_footer" />
</RelativeLayout>
<LinearLayout
android:id="#+id/ll_av_threats"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/rl_button_bar"
android:layout_below="#id/rl_av_found"
android:background="#drawable/tablet_dialog_glow" >
<ListView
android:id="#+id/lv_av_found"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#drawable/tablet_dialog_separator" >
</ListView>
</LinearLayout>
</RelativeLayout>
The OK button is always displayed at the bottom of the screen and the layout's height takes full screen even if I have just one item in the ListView.
How should I structure my xml so as to have its height wrapped according to the content and OK button always visible independent of the number of items in the ListView?
By Default you should have the params as,
Header - Align Top
Body(ListView) - Below header,
Button - below body(ListView)
Now at runtime,
You should get the height of the list view and if it goes beyond the screen, and if it does, then Set the layout params of button to alignParentBottom and layout params of list view to be below header and above button.
Use may use this in vice versa.
To get the height of the list view. Use this
public int getTotalListViewHeight(ListView lv, BaseAdapter ba) {
int listviewElementsheight = 0;
for (int i = 0; i < ba.getCount(); i++) {
View view = ba.getView(i, null, lv);
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
listviewElementsheight += view.getMeasuredHeight();
// for Width use view.getMeasuredWidth()
}
return listviewElementsheight;
}
Here the adapter is listviews adapter.
also will checking this, add the buttons height to the total height.
I'm trying to make a list of LinearLayout become VISIBLE at a click on a "header" LinearLayout.
<LinearLayout android:id="#+id/sample_title" ...>
<TextView ... />
</LinearLayout>
<LinearLayout
android:id="#+id/sample_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:orientation="horizontal"
android:visibility="visible" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:text="Sample text 1"
android:textColor="#color/white" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:orientation="horizontal"
android:visibility="visible" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="left"
android:text="Sample text 2"
android:textColor="#color/white" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</LinearLayout>
Programmatically:
mSampleTitle = (LinearLayout) mView.findViewById(R.id.sample_title);
mSampleTitle.setOnClickListener(this);
mSampleContent = (LinearLayout) mView.findViewById(R.id.sample_content);
[...]
public void onClick(View v) {
if (v == mSampleTitle) {
mSampleContent.setVisibility(mSampleContent.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
}
}
It works fine when there is only one TextView to show, but as soon as there is more, only the first one becomes visible and all the rest is just blank space.
Thank you
My bad, stupid error.
I forgot the android:orientation="vertical". The code changing the VISIBILITY works fine.
<LinearLayout
android:id="#+id/sample_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<LinearLayout
android:id="#+id/sample_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
I still find weird the fact that they were so much blank space below that LinearLayout horizontal...