I have a recyclerview that I would like to share the same background as the activity so that only the textviews inside the recyclerview are visible. I've tried things like this in the cardview and recyclerview xmls:
android:background="#android:color/transparent"
and
android:background="#null"
They haven't worked. Is this possible? I haven't found any answers in previously asked questions on here that have been successful. Any ideas appreciated!
Cardview is for beautifying layout and giving shadow to it, If you don't want to use this feature than you should avoid CardView and use simple LinearLayout, RelativeLayout, ConstraintLayout etc. and than give transparent background to it.
But still you want to use CardView, remove this line
android:background="#android:color/transparent"
and add this line to your CardView.
app:cardBackgroundColor="#android:color/transparent"
If you are using fragment, you need to add it on your container instead of replacing it:
supportFragmentManager.beginTransaction().add(YourFragment(),"tag").commit()
Related
I have just started work with Android Studio 2.2.3. I picked TableLayout and everything looks fine, but I cant drag and drop anything on this layout except TableRow. Even the grid doesn`t show up. Has anybody had the same issue?
I am not clear what exactly you want to implement, if you want to implement grid view then instead of taking table layout take recycler view and implement it as a grid view. to know more about thie follow this link http://www.android-examples.com/android-recyclerview-with-gridview-gridlayoutmanager/
I think you are TableLayout as root layout with these properties: android:layout_width="match_parent"
android:layout_height="match_parent"
So it will occupies you entire Activity. It allows only TableRow because it is child layout for TableLayout.
Try to change the properties as following or change the TableLayout from Root layout and later add the views to layout.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
I wanted to implement the android default button click effect on a Relativelayout. (The material design one)
But the problem is that it works on a view like TextView, But it's not working on a RelativeLayout(I want the relativelayout to have the android default button click effect , just like a normal button ).
I have used :
style="?borderlessButtonStyle"
and
style="?buttonStyle"
But none of them seem to work. They both work on a TextView but not on a Relativelayout. Any thoughts ? Any help is greatly appreciated.
Add this to your layout:
android:background="?android:attr/selectableItemBackground"
Have you added a not null OnClickListener to your RelativeLayout?
And make sure that the layout is clickable with (in xml):
android:clickable="true"
or, in code:
relativeLayout.setClickable(true);
I have a cardview inside which I have several Views which I want to align one below another. For a relative layout I will use the following
layoutParams.addRule(RelativeLayout.BELOW, idofanotherview);
However I cannot find addRule() method for cardview, how do I achieve this?
As the documentation of the CardView states, this component inherits from FrameLayout. That is normal that the addRule() method is unrecognized.
If you really need to use a RelativeLayout to position your subviews then I suggest that you wrap your subviews with one.
This post gives you a good exemple of how to achieve what you need
Good luck!
I'm a beginner Android developer and I'm making my first app. I'd like to make a simple view that is overlayed on the map with a semi-transparent background. This is what it would hopefully look like:
As you can see, one of these dialogs/windows has a simple integer displayed and the other will have a rendered graph/chart.
What would be the best way to go about making this? A dialog? The problem with that might be that I would for the user to be able to work with the mapview below while this is displayed. And I'm not sure if a simple transparent rectangular canvas is the right way to get this done.
Any suggestions/ideas would be much appreciated. Thanks so much.
two ways to go
-Make it a FrameLayout so add MapFragment first then add a Linearlayout with orientation horizontal and make gravity top and translucent background,so it will be displayed on top of map, and it will also involve the elements inside,
-Instead of FrameLayout make it a RelativeLayout and the same process as above.
-Make the overlay as seperate Activity(which is the worst case scenario)
Sample code for overlay can be like this
<LinearLayout
....
android:divider=".." // some drawable or color whatever you want
android:showDividers="middle"
android:orientation="horizontal"
android:background="a000">
<TextView
....
android:value="58"/>
<com.example.custom.view
..../>
</LinearLayout>
I think you can use a RelativeLayout on the top of the MapFragment, with a black background and some opacity (for that you can use a drawable).
Then, on the RelativeLayout you can add other controls like TextView and ImageView
I don't recommand you to use a Dialog, since it sounds like it's not corresponding to your needs.
I am creating an android game, I tried using the canvas.drawText() method to display my score and level but it caused errors. Now I am trying to use TextViews to display them, I am using a SurfaceVeiw and I wanted to know is it possible and would it be a good way of doing it.
You can't really put TextViews into a SurfaceView. What you can do instead, though, is add TextViews on top of the SurfaceView. Let me know if you need help on doing that if you don't know how.
// You can use a FrameLayout to hold the surface view
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(surfaceView);
// Then create a layout to hold everything, for example a RelativeLayout
RelativeLayout relativeLayout= new RelativeLayout(this);
relativeLayout.addView(frameLayout);
relativeLayout.addView(textview1);
relativeLayout.addView(textview2);
setContentView(relativeLayout);
When adding your views, it may be helpful to using LayoutParams to help organize things. Use this documentation for LayoutParams. Hope this helps!
If you're using an XML layout, I would use a RelativeLayout, as mentioned above, contain the SurfaceView inside a FrameLayout. Placing the TextView's on top of the FrameLayout is just a simple matter of configuring the RelativeLayout parameters for each view. You seem new to Android, perhaps this guide will help you with RelativeLayouts and XML layouts in general.