如何控制 addView 到佈局 (How to control addView to a layout)


問題描述

如何控制 addView 到佈局 (How to control addView to a layout)

I add a graphview programatically :

    LinearLayout.LayoutParams Lparams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, p.y/2);

//same result with fill_parent or match_parent

    Lparams.gravity = Gravity.LEFT;

    firstGraph.setPadding(10, 0, 10, 0);

    firstGraph.setLayoutParams(Lparams);

    LinearLayout RelLayout = (LinearLayout) findViewById(R.id.relLayout);

    RelLayout.setGravity(Gravity.LEFT);
    RelLayout.addView(firstGraph, 0);

I obtain this:

What i want is to eliminate that left gap of the graphview, I don't know why is there, I only set a padding of 10 that is what you have in right side.

Any Suggestions? Thansk in advance.

the layout xml:

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="left"
        android:orientation="vertical" >

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />



</LinearLayout>

參考解法

方法 1:

That space most likely appears because it is the space reserved for the axis labels(and as you probably don't set any labels it's an empty space). If you do need to remove it you'll have to modify the graph view's code and change the values in GraphViewConfig(as those seem to be the values used).

方法 2:

setPadding(int left, int top, int right, int bottom) is the sytax of setPadding. The first argument is for the left padding. You are giving 10. Try setPadding(0, 0, 10, 0)

(by J. Arenasuserrahul)

參考文件

  1. How to control addView to a layout (CC BY-SA 3.0/4.0)

#View #padding #Android






相關問題

如何控制 addView 到佈局 (How to control addView to a layout)

ruby on rails 友誼以下節目總是我的名字 (ruby on rails friendship following shows always my name)

Мадэль, вызначаная ў выглядзе? (A model defined in a view?)

android view.getId() 返回 -1 (android view.getId() returns -1)

自定義屬性 select_year 助手或使用 javascript 滾動我自己 (custom attribute select_year helper or roll my own with javascript)

如何清理視圖對象? (How to clean view object?)

為什麼windowController是dealloc但子視圖不是dealloc (why the windowController is dealloc but the subview is not dealloc)

在 Waiting/Loading imageview 上禁用我的標籤欄和導航欄 (disable my Tabbar & Navigationbar of the screen on Waiting/Loading imageview)

DRYing rails 視圖:partial vs helper (DRYing rails view: partial vs helper)

在 SQL 中從 3 個視圖創建一個視圖 (Creating a view from 3 views in SQL)

.net core mvc:在區域上添加具有 crud 功能的控制器未正確生成代碼和鏈接 (.net core mvc: adding controller with crud functionality on area didn't generate code and link correctly)

為什麼segues不起作用?無法切換視圖 (Why segues does not work? can not switch view)







留言討論