android-view

Animation on removeAllViews Android

半腔热情 提交于 2019-12-11 10:25:33
问题 I have a class where I include another layout on a button click. This included layout has some buttons and a code which executes on clicking these buttons. I have used a counter which indicates the number of times the button is clicked. First time clicking on the button includes the layout and the second time clicking removes the views and so on. Here's the code public class Home extends Fragment implements OnClickListener { int c = 0; Button bmain, bnew, bolder; RelativeLayout r1; View

load a layout xml file in a View class android

落爺英雄遲暮 提交于 2019-12-11 09:58:42
问题 I have this class: public class MainActivity extends Activity{ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main);//LOAD MY LAYOUT } } And more code (obviously). And I have the next UI: And I want to draw a line to simulate the union between images. I tried with: Canvas canvas = new Canvas(); Paint paint = new Paint(); paint.setColor(Color.BLACK); canvas.drawLine(0, 0, 300, 700, paint); (The above are just a test to know if I can

Scale a Canvas to fit a View programmatically

怎甘沉沦 提交于 2019-12-11 09:33:35
问题 I'm looking for help with the following scaling problem. I have built my own View class (custom view) which is a child of a Dialog . In this custom view I plot a graph in vertical direction from bottom to top. The graph can be greater or less than the size of the View . Therefore I would like to draw the graph onto the Canvas (which is greater than the View ) using the onDraw() method (see code below) and later scale the Canvas to fit into the View . Things I've tried already include using a

Custom item in the BottomNavigationView

自古美人都是妖i 提交于 2019-12-11 09:05:26
问题 I would like to create a BottomNavigationView with menu with one custom layout item, but this custom layout is not visible in application. This is the menu: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/menu_shopping" android:icon="@drawable/ic_tab_list" android:title="@string/shopping" /> <item android:id="@+id/menu_measurement" android:icon="@drawable/ic_tab_measure" android:title="@string

How to redraw SurfaceView using invalidate() metod?

南楼画角 提交于 2019-12-11 06:45:49
问题 I have a class GameBoard which extends SurfaceView . Inside I have an OnDraw method: @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int size = getWidth()/8; canvasSize = size; pawnBitmap[0] = bigPawn; pawnBitmap[1] = smallPawn; float left_distance; float top_distance; for(int j = 0; j < 10; j++){ for (int i =0; i < 4; i++){ left_distance = i*size+(float)50; top_distance = j*size+(float)10; canvas.drawBitmap(pawnBitmap[0], left_distance, top_distance, paint); canvas

Android, add view with height in percentage

可紊 提交于 2019-12-11 05:42:06
问题 i wanna add a view with a 100% width and X%(e.g: lets make it 40%) to the parent view i have this: private RelativeLayout getParentView(){ return (RelativeLayout) MyActivity.this.getWindow().getDecorView().getRootView(); } i should cast parent view to LinearLayout or RelativeLayout can achieve this ? and how to set 'myView' width and height in percentage programmatically ? Thanks 回答1: You can do this by simply getting the screen width public static int getScreenWidth(Context context) {

Drawing two shapes with transparency in Android/Java

别等时光非礼了梦想. 提交于 2019-12-11 05:05:47
问题 I'm drawing two shapes in Android using paint and canvas. I applied transparency to the paint color, but now when the two shapes (same color) intersect the intersecting section comes out darker. Does anyone know how to accomplish this? Here is a quick look at my paint code (which... should be the only object necessary to complete this I imagine). Paint paint = new Paint(); paint.setColor(color); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStrokeJoin(Paint.Join.ROUND)

Why is my cardview not being drawn onto canvas?

99封情书 提交于 2019-12-11 04:52:06
问题 I'm trying to draw a cardview onto a pdf its canvas. Unfortunately the cardview is not drawn. However some test text is drawn. Why is my carview not drawn? Code: // start a page PdfDocument.Page page = document.startPage(pageInfo); Canvas c = page.getCanvas(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1000, 50); CardView card = new CardView(this); card.setLayoutParams(params); card.setRadius(4f); Bitmap cardBitmap = Utils.loadBitmapFromView(card); c.drawText(

Remove space between menu icon and title

江枫思渺然 提交于 2019-12-11 04:24:50
问题 In the image below, how can I remove the space between the icon and the title of the item in the menu? activity_main_drawer.xml: <?xml version="1.0" encoding="utf-8" ?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:icon="@drawable/ic_exit_to_app" android:id="@+id/logout" android:title="Logout" /> </menu> styles.xml: <?xml version="1.0" encoding="utf-8" ?> <resources> <style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="colorPrimary">@color

How to get actionbar views objects?

断了今生、忘了曾经 提交于 2019-12-11 04:19:41
问题 Is there a way that you can get actionbar views as object references. For instance I would like to get the overflow view in order to know the coordinates on the screen. currently I have manage an ugly solution which is. Get a menu item with an id overflowView =((ViewGroup)parent.findViewById(R.id.menu_id).getParent()).getChildAt(2); 回答1: Is there a way that you can get actionbar views as object references. Only the ones you create yourself, via android:actionLayout and kin. For instance I