So I've checked the other questions to hide a progress bar but all seem to suggest doing what I'm already doing.
I'm trying to use
mProductListProgressBar.setVisibility(View.GONE);
and I'm finding it by
mProductListProgressBar = (ProgressBar) mRoot.findViewById(R.id.product_list_progressbar);
I know it's the correct progress bar as I can move it around the screen before with various LayoutParams commands. But it won't hide.
The current code I have (including the moving of the progress bar) is
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
mProductListProgressBar.setVisibility(View.GONE);
mProductListErrorTextView.setVisibility(View.VISIBLE);
mProductListErrorTextView.setText(errorMessage);
The progress bar moves to left and bottom but is still visible. I have tried View.INVISIBLE as well as View.GONE but neither work.
It's driving me nuts!
Thanks
UPDATE 1
protected void showError(int errorMessage){
/*RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
*/
mProductListProgressBar.setVisibility(View.GONE);
mProductListErrorTextView.setVisibility(View.VISIBLE);
mProductListErrorTextView.setText(errorMessage);
}
and calling it with
showError(R.string.wish_list_empty);
UPDATE 2
xml of fragment
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<GridView
android:id="#+id/product_list_gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:horizontalSpacing="#dimen/standardMargin"
android:listSelector="#android:color/transparent"
android:numColumns="#integer/columns"
android:scrollbarStyle="outsideOverlay"
android:verticalSpacing="#dimen/standardMargin" />
<RelativeLayout
android:id="#+id/product_list_header"
android:layout_width="match_parent"
android:layout_height="#dimen/refineHeaderHeight"
android:background="#drawable/product_list_header"
android:visibility="gone" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:src="#drawable/dropdown_image" />
<TextView
android:id="#+id/product_list_header_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center|left"
android:paddingLeft="10dp"
android:textAllCaps="true"
android:textColor="#android:color/black"
android:textIsSelectable="false"
android:textSize="#dimen/standardTextSize" />
<TextView
android:id="#+id/product_list_refine_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/button"
android:clickable="true"
android:gravity="center_vertical"
android:paddingLeft="20dp"
android:paddingRight="30dp"
android:text="#string/refine"
android:textAllCaps="true"
android:textColor="#838383"
android:textSize="#dimen/standardTextSize" />
</RelativeLayout>
<LinearLayout
android:id="#+id/product_list_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#drawable/product_list_footer"
android:gravity="center"
android:orientation="horizontal"
android:padding="15dp"
android:visibility="gone" >
<ProgressBar
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"
android:gravity="center" />
<TextView
android:id="#+id/product_list_footer_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/loading_message"
android:textAllCaps="true"
android:textSize="#dimen/standardTextSize" />
</LinearLayout>
<ProgressBar
android:id="#+id/product_list_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"/>
<TextView
android:id="#+id/product_list_error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAllCaps="true"
android:textSize="#dimen/standardTextSize"
android:visibility="gone" />
<TextView
android:id="#+id/debug"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#aa000000"
android:gravity="left|center_vertical"
android:minLines="2"
android:padding="10dp"
android:textColor="#android:color/white"
android:visibility="gone" />
</RelativeLayout>
The problem with this behaviour usually happens when your view which you try to hide is needed / referenced by someone else.
In your case, as you mentioned in the comments, you use mProductListProgressBar for setEmptyView() of your GridView.
Another possibility of running into similar troubles when there other views in your relative container layout which set their position relatively to your mProductListProgressBar. This setting could be either in the code or in .xml.
Please make sure you don't have any of above and View.GONE should work fine.
As for setEmptyView() - it is only used to show something meaningful to the user when your adapter is empty. I recommend just setting up simple Layout for that with, say, TextView "no items", in the middle, and pass it to setEmptyView()
Hope that helps.
I know that it is an old question. But I just spent a lot of time debugging similar situation. I could not hide ProgressBar on top of unityPlayer view.
One more thing to ensure is that You are hiding it while in UI thread.
To ensure surround Your UI code with:
runOnUiThread(new Runnable() {
#Override
public void run() {
loadingIndicator.setVisibility(View.GONE);
}
});
A solution that worked for me was to hide the view in XML:
android:visibility="gone"
and then unhide/hide it at runtime when needed:
yourProgressBar.setVisibility(View.VISIBLE) // or View.VISIBLE depending on situation
I don't know how your code is written but had similar problem and resolved by removing the view object from declaration
like
mProductListProgressBar = (ProgressBar) mRoot.findViewById(R.id.product_list_progressbar);
should be
mProductListProgressBar = (ProgressBar) findViewById(R.id.product_list_progressbar);
Try it and check
Reason is the progress bar is on the top of every view in the hierarchy and it's not belong to any root view.
Related
I have a Linear layout then programatically I'm adding some spinners and buttons and so on, but I have xml button Wrap content (width) and then on java I add spinner (or anything else) and it goes below this view even if both views are wrap content:
progBar = new ProgressBar(this);
pBarToca = new ProgressBar(this);
pBarToca.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
linToca = (LinearLayout) findViewById(R.id.tetoca);
linToca.addView(pBarToca);
and it's placed under the button of xml:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_marginTop="6dp"
android:id="#+id/tetoca">
<TextView style="#style/StylePartida"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/te_toca_jugar" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#A7E9A9" android:onClick="callJugar"
android:text="#string/jugar" />
</LinearLayout>
edit!!!!!!
I want textview on first line then on next line button + progressbar (for example)
You have android:orientation=vertical so the Views will be laid out starting at the top and going down.
If you want them to all be next to each other, remove that from your xml since the default orientation for a LinearLayout is horizontal. If you do this, you will obviously need to change the android:width to wrap_content for your TextView or else it will take up the entire screen.
After your comment, a RelativeLayout would work best here.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
style="#style/StylePartida"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/te_toca_jugar"
android:id="#+id/tvID" /> // give it an id
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:id="#+id/tetoca"
android:layout_below="#/id=tvID"> // place it below the TV
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#A7E9A9" android:onClick="callJugar"
android:text="#string/jugar" />
</LinearLayout>
</RelativeLayout>
Note the changes in the comments. Now when you add your progressbar to the LL, it should be next to the Button. You may need some changes but this should give you approximately what you want.
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:id="#+id/tetoca">
<TextView style="#style/StylePartida"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/te_toca_jugar"
android:text="#string/te_toca_jugar" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#A7E9A9" android:onClick="callJugar"
android:text="#string/jugar" />
</LinearLayout>
In your textView you are matching the parent
android:layout_width="match_parent"
This will cause the textview to take up the entire width of the parent view.
android:layout_width="wrap_content"
and
android:orientation="horizontal"
android:orientation="vertical" will cause the elements to be stacked.
If you are using "horizontal" it's important not to have a child element with width matching parent.
EDIT:
After OPs change to question:
I have used a textview, two buttons and listview to give you an idea of how you can format it. There are many ways to achieve the same thing, this is one suggestion.
The internal linearlayout has a horizontal orientation (by default).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="te_toca_jugar"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#A7E9A9"
android:text="jugar"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#A7E9A9"
android:text="jugar2"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lv">
</ListView>
</LinearLayout>
</LinearLayout>
I'm trying to align the seekbar to the top of a view, but i can't center it with the thumb.
Is there some kind of "alignCenter" with the RelativeLayout children.
Here's a sample of my xml code :
<RelativeLayout
android:id="#+id/rl_fragment_audio_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/black_transparent"
android:padding="5dp"
android:visibility="gone" >
<TextView
android:id="#+id/tv_fragment_audio_begin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textColor="#color/white" />
<TextView
android:id="#+id/tv_fragment_audio_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textColor="#color/white" />
<Button
android:id="#+id/btn_fragment_audio_play"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:background="#drawable/btn_play"
android:visibility="gone" />
</RelativeLayout>
<SeekBar
android:id="#+id/sb_fragment_audio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_above="#id/rl_fragment_audio_player" />
For example, Google Play Music does it.
As you said the height of your seekbar might vary, unless you specify it different. Here is how you can make sure it fits all, always.
android:layout_above="#id/rl_fragment_audio_player"
is setting your seekbar bottom above rl_fragment_audio_player top. There is no direct method to specify centerAlignWith but I would remove the space it occupies within it's parent. To know the height of the seekbar you must wait until the global layout has changed. This code should be placed inside your onCreateView
sb = (SeekBar) rootView.findViewById(R.id.sb_fragment_audio);
sb.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener(){
#Override
public void onGlobalLayout() {
sb.getViewTreeObserver().removeOnGlobalLayoutListener(this);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) sb.getLayoutParams();
params.setMargins(0, - sb.getHeight() / 2, 0, - sb.getHeight() / 2);
sb.setLayoutParams(params);
// I suggest you set the seekbar visible after this so that it won't jump
}
});
The last view in the xml will be in the front. Therefore make sure your seekbar is added after the the other views. Like this
<RelativeLayout
android:id="#+id/rl_fragment_audio_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
// your bottom panel
</RelativeLayout>
<View
android:id="#+id/image_above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/rl_fragment_audio_player" />
<SeekBar
android:id="#+id/sb_fragment_audio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/image_above" />
Have you tried adding a negative margin to the seekbar?
<SeekBar
android:id="#+id/sb_fragment_audio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginBottom="-15dp"
android:layout_above="#id/rl_fragment_audio_player" />
I am showing and hiding views on a particular actions using some animation, I used LayoutTransition and it seems to work fine except one thing, while the animation is going, the background of some TextViews changes and reset to the default white background!!
Following is the code I am using to apply animation after hide/show.
mRightTransitioner = new LayoutTransition();
mRightTransitioner.setDuration(1000);
vg_rightContainer.setLayoutTransition(mRightTransitioner);
Edited: even without animation i tried, same problem, the background resets once view's position changes
Edited: here how i declared the views in the XML
<LinearLayout
android:id="#+id/ll_req_reasonwrapper"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:gravity="right"
android:orientation="horizontal"
android:visibility="gone" >
<EditText
android:id="#+id/et_req_reasons"
android:layout_width="400dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:gravity="right|center_vertical"
android:inputType="text"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_preasons" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_req_timewrapper"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:gravity="right"
android:orientation="horizontal"
android:visibility="gone" >
<LinearLayout
android:id="#+id/ll_req_endtimewrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/ftv_req_endtime"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:freezesText="true"
android:gravity="right|center_vertical"
android:inputType="numberDecimal"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_endtime" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_req_starttimewrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="50dp" >
<TextView
android:id="#+id/ftv_req_starttime"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#drawable/comments_textbox"
android:freezesText="true"
android:gravity="right|center_vertical"
android:inputType="numberDecimal"
android:paddingRight="8dp" />
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="#string/str_req_starttime" />
</LinearLayout>
</LinearLayout>
for instance: if i hide 'll_req_reasonwrapper', then the LinearLayout 'll_req_timewrapper' moves up, then the backgrounds of the textViews like 'ftv_req_starttime' becomes white!!
Please help.
Edited Answer:
if your are using linear layout then if the child is not being displayed, it is not going to be laid out and not going to be the part of the measurements ( as it looks like ). I recommend to use the RelativeLayout.
You can try
android:background="#null"
for your buttons. if your are using some custom class for button then add
.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
for this specific views.
Need more code. The fact that disabling the LayoutTransition does not solve your issue, means that the animation is not the issue.
How do you reinstantiate child views or populate your view. Are you removing views with setVisibility(View.GONE) and then setting them back with setVisibility(View.VISIBLE)
OR
Are you removing childAt(i) and then dynamically adding custom views
I'm sorry I couldnt add a comment since I dont have the reputation for that but I think I am able to answer your question if you post more code.
I'm programatically adding views into my layout inside a for loop.
The xml file of the layout I'm adding is like this one:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout_consulta_item_list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView_consulta_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/LinearLayout_dados_consulta"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/LinearLayout_dados_consulta"
android:layout_centerHorizontal="true"
android:layout_centerInParent="false"
android:adjustViewBounds="true"
android:maxWidth="70dp"
android:padding="10dp"
android:scaleType="centerInside"
android:src="#drawable/estrela_off" />
<LinearLayout
android:id="#+id/LinearLayout_dados_consulta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_toLeftOf="#+id/imageView_consulta_action"
android:background="#660000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="#string/origem"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffaaaa"
android:textSize="10sp" />
<TextView
android:id="#+id/textView_origem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YYY"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#eeeeee" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:text="#string/data_ida"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffaaaa"
android:textSize="10sp" />
<TextView
android:id="#+id/textView_data_ida"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2014-05-05"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#eeeeee"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
In my main_activity, I call the constructor:
for (int i=0;i<resultList.length-1;i++){
RelativeLayout viewToLoad = (RelativeLayout)LayoutInflater.from(this).inflate(R.layout.consulta_item, null);
ll.addView(viewToLoad);
ImageView ImgConsulta_action = (ImageView)findViewById(R.id.imageView_consulta_action);
LinearLayout dados_consulta = (LinearLayout)findViewById(R.id.LinearLayout_dados_consulta);
dados_consulta.setOnLongClickListener(...);
ImgConsulta_action.setOnLongClickListener(...);
Well, I keep setting SetText for all the views in the layout and so on.
But, in order to make the setOnClickListener to work for each view, I must set a id to the views inside the for loop:
dados_consulta.setId(4000+i);
ImgConsulta_action.setId(5000+i); //(*lastline)
The weird thing is happening is that:
If I comment this last line, the layout is inserted correctly with the imageview showing a star as it is suposed to do and the listener at "dados_consulta" works fine.
But if I remove the comment at this last line, the star dissapear from the screen.
Can anybody help me to understand what is going on?
I had an layout params referenced to the ID of the layout elements at the original view.
Since I have to change the ID dynamically while I'm adding this layout several times into my activity, I also need to reset the layoutparams to the new Ids.
So, I added this lines:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)ImgConsulta_action.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_TOP, dados_consulta.getId());
params.addRule(RelativeLayout.ALIGN_BOTTOM, dados_consulta.getId());
ImgConsulta_action.setLayoutParams(params);
RelativeLayout.LayoutParams paramsDadosConsulta = (RelativeLayout.LayoutParams)dados_consulta.getLayoutParams();
paramsDadosConsulta.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
paramsDadosConsulta.addRule(RelativeLayout.LEFT_OF, ImgConsulta_action.getId());
dados_consulta.setLayoutParams(paramsDadosConsulta);
Now it's working perfectly.
Notice that the problem is not about the layout disappearing it was about a layout get in front of the other one. (making this other one invisible)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<Button
android:id="#+id/insertButtonVIEW"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="insert" />
<Button
android:id="#+id/removeButtonVIEW"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="remove" />
</LinearLayout>
</RelativeLayout>
Sometimes, depending on a situaiton, I am hiding removeButtonVIEW using the method setVisibility(View.INVISIBLE);
When that happens, I want to my insertButtonVIEW to take the whole width of the screen (when the two are present, each one takes 50% of the screen).
Since this might or might not happen, I am doing these changes programmatically.
I tried the following methd which worked, however, it is causing for all the interface to go jumbo mumbo, as everything's location on the screen is getting mixed.
modifyButton.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
Any hints ?
UPDATE 1 after applying the answer :
I am using the following code to set the button to invisible.
Bundle extras;
extras = getIntent().getExtras();
String answer = extras.getString("answer");
if(answer.equalsIgnoreCase("yes")
{
insertButton.setEnabled(true);
insertButton.setText("INSERT");
removeButton.setVisibility(View.INVISIBLE);
}
else
{
//whatever
}
// I Have modify your code now try this one and you don't required set LayoutParams ().
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<Button
android:id="#+id/insertButtonVIEW"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="insert" />
<Button
android:id="#+id/removeButtonVIEW"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="remove" />
</LinearLayout>
</RelativeLayout>
if(answer.equalsIgnoreCase("yes")
{
insertButton.setEnabled(true);
insertButton.setText("INSERT");
removeButton.setVisibility(View.GONE);
}
else
{
//whatever
}
Use
setVisibility(View.GONE);
*Remove this *
modifyButton.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
And set
android:layout_width="0dp"
in both button