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"
Related
I´m a bit lost.
I´m developping my first Android app, and I´m not sure about the better way to implement some activities.
No my problem is than in my app, I have to divide the screen in two equals parts, one side for each player. Each side has two TextView, some buttons, etc, the same for both player, but one the sides rotated 180 degrees relative to the other.
What would be the better way to do that?
Define a whole layout and repeat the same layout inside for each player? I think this would be the worst solution because the management of the listeners for the views would be duplicated and more complicated.
Use a layout to define the player views and put it in a ListView or Table with two items/rows, using a custom adapter to unify the management of the listeners? In this case I don´t know how to divide the screen in two equals parts and fit the whole screen...
Use fragments, defining a fragment to define the player a put it twice in the layout?
Another idea.....
Could anyone help me and tell me the better way to do that in Android and the better way in terms of management and performance?
Thanks in advance.
I finally decided to use the include tag in my root layout this way:
<LinearLayout 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:padding="10dip"
android:orientation="vertical"
tools:context="com.example.cdp.mispartidas.actividades.Duel">
<include android:id="#+id/player0"
android:layout_gravity="top"
android:rotation="180"
android:layout_weight="1"
android:layout_marginBottom="10dp"
layout="#layout/player_duel"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/holo_blue_dark"/>
<include android:id="#+id/player1"
android:layout_gravity="bottom"
android:layout_weight="1"
android:layout_marginBottom="10dp"
layout="#layout/player_duel"/>
Now my doubt is the better way to manage the listeners. In the "player_duel" layout I have two buttons that modify the content of a TextView, another button for another task, and Dialog that has to appear when click on the TextView, etc.
Now I have all the View duplicated. I can identify then by using the corresponding layout, but how I could unify the event listeners management?
Regards
player_duel.xml
<LinearLayout>
<TextView android:id="#+id/tv_0"/>
<Button android:id="#+id/btn_0"/>
<Button android:id="#+id/btn_1"/>
<Button android:id="#+id/btn_2"/>
</LinearLayout>
OnClickListner listener = new OnClickListener(){
public void onClick(View v){
if(v.getParent()!=null && v.getParent().getId() == R.id.player0){
swicth(v.getId()){
case R.id.tv_0:
break
case R.id.btn_0:
break
case R.id.btn_1:
break
case R.id.btn_2:
break
}
}else if(v.getParent()!=null && v.getParent().getId() == R.id.player1){
......
}
}
};
((ViewGroup)findViewById(R.id.player0)).findViewById(R.id.tv_0).setOnClickListener(listener);
......
This is the layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp">
<RelativeLayout
android:id="#+id/leftside"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="vertical"
android:layout_gravity="left"
android:padding="10dp">
<ImageButton android:id="#+id/diceduel"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/dice"
android:scaleType="center"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_gravity="top"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<ImageButton android:id="#+id/changeduel"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_autorenew_white_24dp"
android:background="#drawable/roundbutton"
android:scaleType="fitXY"
android:padding="10dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_gravity="bottom"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_alignParentBottom="true" />
<TextView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/diceresult"
android:textAlignment="center"
android:layout_below="#+id/diceduel"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textSize="30dp"
android:gravity="center" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_weight="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/playername"
android:gravity="center"
android:paddingTop="10dp"
android:textSize="20dp"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/scoreduel"
android:layout_alignParentLeft="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:textSize="100dp"
android:layout_weight="1"
android:textStyle="bold"
android:maxLines="1"
android:ellipsize="none"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:layout_below="#+id/playername"
android:layout_alignParentBottom="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rightside"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="vertical"
android:layout_gravity="right"
android:padding="10dp">
<ImageButton android:id="#+id/sumduel"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_add_white_24dp"
android:background="#drawable/roundbutton"
android:scaleType="fitXY"
android:padding="10dp"
android:layout_gravity="top"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<ImageButton android:id="#+id/substractduel"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_remove_white_24dp"
android:background="#drawable/roundbutton"
android:scaleType="fitXY"
android:padding="10dp"
android:layout_gravity="bottom"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false" />
</RelativeLayout>
I finally found the solution by defining the two-views array and using the "fake" viewholder. I define a listener for all the common views in the layout, and store the index as property in the constructor, so in the listener I only have to refer the proper item in the array with the index.
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.
I have a problem setting up layout.
Before AD is loaded it looks like this:
After AD is loaded, everything goes to it's place. It looks like this ( correct )
Does anybody know how to fix this problem? Not that only looks "ugly" for the time which AD is loading, but AD may never be loaded also, and layout could stay this way (first image )forever.
Any suggestions?
I have this XML layout:
<com.example.touch.TouchImageView android:id="#+id/mytouchview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_above="#+id/relat"
/>
<RelativeLayout
android:id="#id/relat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_above="#+id/myAdView"
>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentLeft="true"
android:background="#null" android:src="#drawable/previous" android:id="#+id/previous"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="2/15"
android:id="#+id/memeNumber" android:layout_centerInParent="true" android:layout_margin="5dp"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentRight="true"
android:background="#null" android:src="#drawable/next" android:id="#+id/next"/>
</RelativeLayout>
<com.csjy.sfwn148282.AdView
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:id="#id/myAdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ap:animation="fade"
ap:placementType="interstitial"
ap:banner_type="inappad"
ap:test_mode="true"
ap:canShowMR="false"
android:layout_alignParentBottom="true"
/>
EDIT:
After #Szymon answer layout looks like this. It's okay because it's the same while loading the AD. The problem is that now, buttons are missing..
Change your top level Relative Layout to a linear Layout (vertical) and then use layout_weight on the three layouts. set the layout_weight for mytouchview to 1 and the other two to 0. This will give mytouchview all the extra space and push the buttons and ad to the bottom. When the ad takes up space it will push the button tray up appropriately, but it won't take any space if the ad never loaded.
Try that one:
<?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" xmlns:app="http://schemas.android.com/apk/res/example.com">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="#+id/myAdView"
android:orientation="vertical" >
<com.example.touch.TouchImageView android:id="#+id/mytouchview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
/>
<RelativeLayout
android:id="#id/+relat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentLeft="true"
android:background="#null" android:src="#drawable/previous" android:id="#+id/previous"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="2/15"
android:id="#+id/memeNumber" android:layout_centerInParent="true" android:layout_margin="5dp"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentRight="true"
android:background="#null" android:src="#drawable/next" android:id="#+id/next"/>
</RelativeLayout>
</LinearLayout>
<com.csjy.sfwn148282.AdView
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:id="#id/myAdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ap:animation="fade"
ap:placementType="interstitial"
ap:banner_type="inappad"
ap:test_mode="true"
ap:canShowMR="false"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
I have a question. I am working on a layout wherein I want one layout to be above the other layout.
Situation: There is one RelativeLayout which has a Touchlistener. At the bottom of this layout, there is anothet relative layout having three buttons which are clickable. Now the problem is when I click on one these buttons, the listener of the first layout gets activated and none of the buttons work.
I did make use of frame layout but its not working. Did make use of .bringToFront method. But this did not work also.
Please I need suggestions for the same.
I am uploading my code.
<RelativeLayout
android:id="#+id/rlayout"
android:layout_width="458dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:gravity="center"
android:layout_height="278dp"
android:background="#drawable/anim_layout" >
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:scaleType="centerInside"
android:visibility="visible" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:gravity="center"
android:scaleType="centerInside"
android:visibility="invisible" />
</RelativeLayout>
<ImageView
android:id="#+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_gravity="bottom"
android:background="#drawable/image_unfocus" />
<RelativeLayout
android:id="#+id/rlayout_anim_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="4dp"
android:background="#drawable/anim_bg" >
<ImageButton
android:id="#+id/sequence_image"
android:layout_width="22dip"
android:layout_height="17dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="3dip"
android:background="#drawable/unfocus_image" />
<ImageView
android:id="#+id/edit_image"
android:layout_width="22dip"
android:layout_height="17dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="80dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="#id/sequence_image"
android:background="#drawable/edit_icon" />
<ImageView
android:id="#+id/close_image"
android:layout_width="22dip"
android:layout_height="17dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="130dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="#id/edit_image"
android:background="#drawable/close_img" />
</RelativeLayout>
use Layout Inflator ... make an xml . with the use of inflator , you can inflate another layout over the previous one.
enjoy
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.