更改setContentView时

时间:2015-07-26 16:34:29

标签: android fragment

如果我在片段中,我可以更改setContentView

 @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.j_01_list);
            new ProgressTask(jornada.this).execute();
        }

2 个答案:

答案 0 :(得分:0)

如果您是Fragment,则可以将您的视图设置为onCreateView(),如

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.j_01_list, container, false);
    }

但只有从 FRAGMENT

延伸才会发生这种情况

Fragment

的示例
public class TestFragment extends Fragment {

 View rootView;

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.j_01_list, container, false);

     return rootView;
     } 
 }

有关详细信息,请查看此Fragment DocumentationonCreateView() Documentation

答案 1 :(得分:0)

var buttonState = document.getElementById("clickMe");
var maxWidth = screen.width;
var maxHeight = screen.height;
var screenWidth = 0;
var screenHeight = 0;
// Find max width and height of screen and set variables to random number within parameters
function moveButton() {
    "use strict";
    screenWidth = Math.floor(Math.random() * (maxWidth - 1 + 1)) + 1;
    screenHeight = Math.floor(Math.random() * (maxHeight - 1 + 1)) + 1;
}
buttonState.onClick = function () {
    "use strict";
    movebutton();
    buttonState.style.left = screenWidth.page + "px";
    buttonState.style.top = screenHeight.page + "px";
    console.log(screenWidth);
    console.log(screenHeight);         
};