ScrollView hides top elements of the layout - android

I have pretty simple dialog layout and added scrollview because dialog can be quite long and not fit into the screen
When I initially run the dialog (it fits the screen) everything is fine, then I change device orientation to landscape, dialog does not fit to screen anymore, scrolling appears, but several top elements (up to #+id/addr_label) become invisible though some empty space appears between Title and first visible element exist. The most confusing thing is- when I change device back to portrait view- these elements are still invisible.
UPDATE: Just checked the case when phone is initially in landscape mode- in this case all elements are shown correctly. when I change it back to portrait- the elements disappear. seems to be a "change orientation" bug
What can be a problem?
Layout and screenshots are below (Android is 2.3.5)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root22" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:padding="0dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="10dp">
<TextView android:id="#+id/details_ssid"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="5dip"/>
<TextView android:id="#+id/details_bssid"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text=""
android:layout_weight="1"
android:layout_marginLeft="5dip"/>
<TextView android:id="#+id/latitude"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text=""
android:layout_weight="1"
android:layout_marginLeft="5dip"/>
<TextView android:id="#+id/longitude"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text=""
android:layout_weight="1"
android:layout_marginLeft="5dip"/>
<TextView android:id="#+id/addr_label"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/address_label"
android:layout_weight="1"
android:layout_marginLeft="5dip"/>
<EditText android:id="#+id/address"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text=""
android:layout_weight="1"
android:layout_marginLeft="5dip"/>
<TextView android:id="#+id/descr_label"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/description_label"
android:layout_weight="1"
android:layout_marginLeft="5dip"/>
<EditText android:id="#+id/description"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text=""
android:layout_weight="1"
android:layout_marginLeft="5dip"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp">
<Button
android:id="#+id/yes"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dip"
android:layout_marginRight="10dip"
android:text= "#string/Yes"
android:visibility="visible"
/>
<Button
android:id="#+id/no"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dip"
android:layout_marginRight="10dip"
android:text= "#string/No"
android:visibility="visible"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Code is pretty boring:
onCreateDialog in Activity which sets layout and
onPrepareDialog whic sets values to all these fields
onCreateDialog
case CONFIRM_SHARE_AP:
{
final Dialog dialog = new Dialog(this){
public void onBackPressed()
{
dismissDialog(CONFIRM_SHARE_AP);
}
};
dialog.setContentView(R.layout.ap_add_confirmation);
dialog.setTitle(R.string.confirm_share);
Button cancel = (Button) dialog.findViewById(R.id.no);
cancel.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
dismissDialog(CONFIRM_SHARE_AP);
}
});
return dialog;
}
onPrepareDialog
has nothing specific at all
http://img525.imageshack.us/img525/4642/devicev1.png
http://img13.imageshack.us/img13/985/devicev2.png

Found a root of the prob.
This is because during orientation change activity is restarted (by default) and therefore dialogs are recreated.

Related

Android slider drawer custom icon position

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal"
android:rotation="180" >
<ImageView
android:id="#id/handle"
android:layout_width="50dip"
android:layout_height="50dip"
android:rotation="180"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#id/content"
android:layout_width="250dp"
android:layout_height="fill_parent"
android:background="#0000ff"
android:orientation="vertical"
android:rotation="180" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
</LinearLayout>
</SlidingDrawer>
I want to change the icon position and put it on the top position from left to right
Is anyone who can tell me how it to set this custom icon position on android slider drawer>
Thanks in advance
http://i.stack.imgur.com/q8dz2.png
Take a look at your button:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
You can set for it an icon in at least four ways (like in this picture):
You need only to specify where the Drawable should stay.
on the left of text:
android:drawableLeft="#mipmap/ic_launcher"
on the right of text:
android:drawableRight="#mipmap/ic_launcher"
at the top, text below:
android:drawableTop="#mipmap/ic_launcher"
at the bottom, text above:
android:drawableBottom="#mipmap/ic_launcher"
All you need is to add to your button layout one of these possible lines.
Of course to one button, you can add more than one drawable.
NOTE: Read also:
http://developer.android.com/guide/topics/ui/controls/button.html
Hope it help
EDIT: I haven't used SlidingDrawer before, so I cannot recognize, where the problem is, but always you can do a trick like this
<Button
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:drawableTop="#mipmap/ic_launcher"
android:layout_alignParentLeft="true"
android:layout_below="#id/handle"
android:background="#0000ff"
/>
This is a button with your desired image and "transparent" background.
Try it now and I would look for another solution ;-)
SOLUTION: Please try this code:
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal"
android:rotation="180" >
<ImageView
android:id="#id/handle"
android:layout_width="50dip"
android:layout_height="50dip"
android:rotation="180"
android:src="#mipmap/ic_launcher" />
<LinearLayout
android:id="#id/content"
android:layout_width="250dp"
android:layout_height="fill_parent"
android:background="#0000ff"
android:orientation="vertical"
android:rotation="180" >
<ImageView
android:id="#id/handle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
If you still have any question please free to ask
Sliding drawer is deprecated, and is hard to use but I made a replacement. The only problem about it is that it doesn't slide like the sliding drawer, but it does apear and disapear. Here is the XML part:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:background="#acacac"
android:layout_height="100dp"
android:id="#+id/etc"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu"
android:id="#+id/bMenu"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:background="#drawable/button_shape_1"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/etc"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="gone"
android:id="#+id/menuContent">
//content
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
This will by default(on copy/paste) not be shown(half the point)
It must be a framelayout as they allow item to be layed on top of eachother(the root element that is)
The code part:
RelativeLayout menuContent;
Button showMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
menuContent = (RelativeLayout) findViewById(R.id.menuContent);
showMenu = (Button) findViewById(R.id.bMenu);
showMenu.setOnClickListener(this);
}
boolean menuActive = false;
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bMenu:
if(menuActive){
menuActive = false;
menuContent.setVisibility(View.GONE);
}else if(!menuActive){
menuActive = true;
menuContent.setVisibility(View.VISIBLE);
}
break;
}
}
This was copied out of a part of one of my newest games, so if it doesn't work as it sits, let me know and I will take a look at it

setVisibility(view.GONE) is not working Android

i need to disable the view programmatically so i used setVisibility(view.GONE) in activity. My xml have two buttons named lower and upper and two relative layouts named lower_lay and upper_lay.when i click the lower button i need enable lower_lay and i click the upper button i need to enable upper_lay. Both in upeer_lay and lower_lay having images and performing onTouch event. Now my problem is when i am in lower_lay the images of upper_lay are disabled but when i touch the empty space in lower_lay, upper_lay images are coming...and in upper_lay i am having this issue. Why the view is not completelt gone?
i am trying this from 3 days....please any one help me out.
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/r1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e356a">
<TextView
android:id="#+id/placce_head"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Hyderabad to banglore"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Selected Seats"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/totalamount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Total Amount"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seat_num"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/total_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#1e356a"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e356a"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:src="#drawable/bluesmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:text="Available"
android:textSize="12dp"
android:textColor="#ffffff"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#drawable/greensmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:textSize="12dp"
android:textColor="#ffffff"
android:text="Selected"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:src="#drawable/pinksmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ladies"
android:textSize="12dp"
android:textColor="#ffffff"
android:layout_marginLeft="6dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:src="#drawable/redsmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:textSize="12dp"
android:textColor="#ffffff"
android:text="Booked"/>
</LinearLayout>
<LinearLayout
android:id="#+id/sleeper_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#78869c"
android:weightSum="2"
android:padding="7dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:id="#+id/lower"
android:layout_width="0dp"
android:layout_weight="1"
android:text="Lower"
android:textColor="#F93249"
android:gravity="center"
android:textSize="18dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/upper"
android:layout_width="0dp"
android:layout_weight="1"
android:text="Upper"
android:textSize="18dp"
android:textColor="#ffffff"
android:gravity="center"
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relative_layout"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/bg_border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/relative_layout_two"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/bg_border"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
</RelativeLayout>
<Button
android:id="#+id/done_btn"
android:background="#F93249"
android:textColor="#ffffff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="done"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Activitiy:
lower_lay = (RelativeLayout) findViewById(R.id.relative_layout);//lower layout
upper_lay= (RelativeLayout) findViewById(R.id.relative_layout_two);//upperlayout
upper.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
lower_lay.setVisibility(View.GONE);
upper.setTextColor(Color.parseColor("#F93249"));
lower.setTextColor(Color.parseColor("#ffffff"));
upper_lay.setVisibility(View.VISIBLE);
sheetdetails.clear();
}
});
lower.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
upper_lay.setVisibility(View.GONE);
upper.setTextColor(Color.parseColor("#ffffff"));
lower.setTextColor(Color.parseColor("#F93249"));
lower_lay.setVisibility(View.VISIBLE);
}
});
Try using
View.GONE
not
view.GONE
and lower.setOnClickListener not lower.setOnTouchListener
View is the class, so should starts with capital letter.
Kindly see my updates.
upper.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
lower_lay.setVisibility(View.GONE);
upper.setTextColor(Color.parseColor("#F93249"));
lower.setTextColor(Color.parseColor("#ffffff"));
upper_lay.setVisibility(View.VISIBLE);
}
});
lower.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
lower_lay.setVisibility(View.VISIBLE);
upper.setTextColor(Color.parseColor("#ffffff"));
lower.setTextColor(Color.parseColor("#F93249"));
upper_lay.setVisibility(View.GONE);
}
});
I will give you a good advice about your layout:
From Chat Haase blog:
RelativeLayout is a very convenient layout to use, because it allows
developers to specify how content should be placed relative to other
content. In many situations, this is necessary and may be the best
solution for the job. However, it is important to understand that
RelativeLayout is an expensive solution, because it requires two
measurement passes to ensure that it has handled all of the layout
relationships correctly. Moreover, this problem compounds with every
additional RelativeLayout throughout the hierarchy. Imagine a
RelativeLayout at the top of your view hierarchy; this essentially
doubles the measurement work on your entire view hierarchy. Now
imagine another RelativeLayout as one of the children of that first
one — this doubles again the measurement passes that happen under it,
requiring four measurement passes for all of the views in its
sub-hierarchy.
Use a different type of layout for situations that do not require the
capabilities of RelativeLayout, such as LinearLayout or even a custom
layout. Or for situations in which relative alignment of child views
is necessary, consider the more optimized GridLayout, which
pre-processes the child view relationships and avoids the
double-measurement problem.

How to set textView as right as possible and set textView show only a part of text?

I have the xml code shown below. Everything is working as it should except the final textView( id locationTextView) which won't stay right. I want it to stay as right as possible, but I can't do that(it still appears straight after the linear Layout).Should I set a left margin?. And for the textView1 how can I make it to show only a certain part of the whole text, because I have texts of different lengths and they ruin the layout.
<?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"
android:background="#color/product_list_item_bg"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/icon"
android:layout_width="72dip"
android:layout_height="72dip"
android:layout_margin="3dip"
android:adjustViewBounds="true"
android:contentDescription="#string/descr_image"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#33CC33" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView" />
</LinearLayout>
<TextView
android:gravity="right"
android:layout_width="72dip"
android:layout_height="72dip"
android:layout_marginTop="0dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/locationTextView"
android:layout_gravity="right" />
</LinearLayout>
</RelativeLayout>
Try android:layout_weight="1" or some other value for your locationTextView. You can also try out android:weightSum="3" (or that is appropriate instead of 3) on your root LinearLayout. Assign proper weights to your different child views. You can get help here
For showing text in a presentable way, you could use android:ellipsize="marquee" or other options available.

XML listview overlaps elements when setting visibility

I have an xml layout of about 3000 lines, which serves as the layout for a questionnaire type of app. Each page of the questionnaire is inside of a different linear layout and I set the visibility of the linear layouts in code using View.GONE or View.VISIBLE. This way the user can navigate through the pages without loading new intents each time.
However, when I navigate fast through the app (just pressing the next button to go through the screens), some of the elements that are supposed to be View.GONE shows up and overlaps over the VISIBLE items. This only happens with linear layouts that have list views inside of them. For all the other pages.
I can scroll fast through them, but just the ones with list views in the View.GONE elements sometimes shows up when I navigate too fast. How can I fix this ? Let me know if you want code ... however the xml is very large.
T.I.A.
EDIT
This is a sample of my xml code, I have 3000 lines of this repeating in my xml...
<LinearLayout
android:id="#+id/package_normal_samplesblood"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="70dp"
android:orientation="vertical">
<TextView
android:id="#+id/textview_heading_b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23sp"
android:layout_marginLeft="13dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:textColor="#6f6f6f"
android:layout_gravity="left"
android:text="Blood Samples"/>
<Button
android:id="#+id/button_samples_blood"
android:text="Add Blood Samples"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:textSize="20sp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<ListView
android:id="#+id/listview_samples_blood"
android:scrollbarSize="0dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
/>
</LinearLayout>
<RelativeLayout
android:orientation="horizontal"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_marginTop="-75dp"
>
<View
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_height="1dp"
android:background="#DEDEDE"
android:layout_marginTop="2dp"/>
<ImageButton
android:id="#+id/left9"
android:background="#null"
android:scaleType="fitEnd"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="70px"
android:layout_height="70px"
android:src="#drawable/left"/>
<TextView
android:id="#+id/textview_heading2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:textColor="#6f6f6f"
android:layout_gravity="center"
android:text="RhODIS®"/>
<ImageButton
android:id="#+id/right9"
android:background="#null"
android:scaleType="fitEnd"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_width="70px"
android:layout_height="70px"
android:src="#drawable/right"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/package_normal_sampleshair"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="70dp"
android:orientation="vertical">
<TextView
android:id="#+id/textview_heading_b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23sp"
android:layout_marginLeft="13dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:textColor="#6f6f6f"
android:layout_gravity="left"
android:text="Hair Samples"/>
<Button
android:id="#+id/button_samples_hair"
android:text="Add Hair Samples"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:textSize="20sp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<ListView
android:id="#+id/listview_samples_hair"
android:scrollbarSize="0dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
/>
</LinearLayout>
<RelativeLayout
android:orientation="horizontal"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_marginTop="-75dp"
>
<View
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_height="1dp"
android:background="#DEDEDE"
android:layout_marginTop="2dp"/>
<ImageButton
android:id="#+id/left10"
android:background="#null"
android:scaleType="fitEnd"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="70px"
android:layout_height="70px"
android:src="#drawable/left"/>
<TextView
android:id="#+id/textview_heading2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:textColor="#6f6f6f"
android:layout_gravity="center"
android:text="RhODIS®"/>
<ImageButton
android:id="#+id/right10"
android:background="#null"
android:scaleType="fitEnd"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_width="70px"
android:layout_height="70px"
android:src="#drawable/right"/>
</RelativeLayout>
</LinearLayout>
And then this is a sample of how I show and hide the linear layouts in code, this repeats for 24 left buttons and 24 right buttons:
left24.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
package_normal_welcomescreen.setVisibility(View.GONE);
package_normal_package_details.setVisibility(View.GONE);
package_normal_openbag.setVisibility(View.GONE);
package_normal_kitnumber.setVisibility(View.GONE);
package_normal_emptybag.setVisibility(View.GONE);
package_normal_gpscoordinates.setVisibility(View.GONE);
package_normal_image_scene.setVisibility(View.GONE);
package_normal_samplesblood.setVisibility(View.GONE);
package_normal_sampleshair.setVisibility(View.GONE);
package_normal_samplestissue.setVisibility(View.GONE);
package_normal_sampleshorn.setVisibility(View.GONE);
package_normal_samplesother.setVisibility(View.GONE);
package_normal_packsamples.setVisibility(View.GONE);
package_normal_returnbag.setVisibility(View.GONE);
package_normal_sealreturnbag.setVisibility(View.GONE);
package_normal_image_sealedbag.setVisibility(View.GONE);
package_normal_scanned.setVisibility(View.GONE);
package_normal_animal_details.setVisibility(View.GONE);
package_normal_animal_horn_details.setVisibility(View.GONE);
package_normal_animal_ears.setVisibility(View.GONE);
package_normal_area_details.setVisibility(View.GONE);
package_normal_collecter_details.setVisibility(View.GONE);
package_normal_additional_information.setVisibility(View.GONE);
package_normal_owner_details.setVisibility(View.VISIBLE);
package_normal_owner_details.bringToFront();
}
});
right24.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(Session.signatureIsCaptured)
{
package_normal_welcomescreen.setVisibility(View.GONE);
package_normal_package_details.setVisibility(View.GONE);
package_normal_openbag.setVisibility(View.GONE);
package_normal_kitnumber.setVisibility(View.GONE);
package_normal_emptybag.setVisibility(View.GONE);
package_normal_gpscoordinates.setVisibility(View.GONE);
package_normal_image_scene.setVisibility(View.GONE);
package_normal_samplesblood.setVisibility(View.GONE);
package_normal_sampleshair.setVisibility(View.GONE);
package_normal_samplestissue.setVisibility(View.GONE);
package_normal_sampleshorn.setVisibility(View.GONE);
package_normal_samplesother.setVisibility(View.GONE);
package_normal_packsamples.setVisibility(View.GONE);
package_normal_returnbag.setVisibility(View.GONE);
package_normal_sealreturnbag.setVisibility(View.GONE);
package_normal_image_sealedbag.setVisibility(View.GONE);
package_normal_scanned.setVisibility(View.GONE);
package_normal_animal_details.setVisibility(View.GONE);
package_normal_animal_horn_details.setVisibility(View.GONE);
package_normal_animal_ears.setVisibility(View.GONE);
package_normal_area_details.setVisibility(View.GONE);
package_normal_owner_details.setVisibility(View.GONE);
package_normal_collecter_details.setVisibility(View.GONE);
package_normal_additional_information.setVisibility(View.VISIBLE);
package_normal_additional_information.bringToFront();
}
else
{
Toast.makeText(Screen_Package_Normal.this, "Authorized Signature Required", Toast.LENGTH_LONG).show();
}
}
});
I have different types of listviews and adapters, custom and android built in. I don't think the problem lies with the adapter since it works pretty well displaying the listviews and the problem occurs even before the listviews are populated...
I have a temporary fix, not sure how correct this is as an answer, but this fixed my problem... I applied this to my entire layout, and it adds an animation when I hide and show layouts, thus slowing them down a bit, removing the overlapping elements from showing up.
This is what I added to my layout:
android:animateLayoutChanges="true"

Android - Collapsible LinearLayout with multiple items

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...

Categories

Resources