我有一个观点TableLayout, TableRow and TextView.我希望它看起来像一个网格.我需要得到这个网格的高度和宽度.这些方法getHeight()和getWidth()总是返回0.这发生在我和动态也格式化网格时我使用XML版本.
如何检索视图的尺寸?
这是我在Debug中用来检查结果的测试程序:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TextView;
public class appwig extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maindemo); //<- includes the grid called "board"
int vh = 0;
int vw = 0;
//Test-1 used the xml layout (which is displayed on the screen):
TableLayout tl = (TableLayout) findViewById(R.id.board);
tl = (TableLayout) findViewById(R.id.board);
vh = tl.getHeight(); //<- getHeight returned 0, Why?
vw = tl.getWidth(); //<- …Run Code Online (Sandbox Code Playgroud) 我有两个片段Frag A和Frag B,它们使用view pager呈现.如果用户从A滑动到B然后按下后退按钮(在B中),则用户应该转到A而不是离开视图寻呼机.我们怎样才能做到这一点?
向Backstack添加事务似乎没有帮助.
谢谢
我正在使用ViewPager在我的Android应用程序中实现滑动.但是,我想在用户使用后退按钮而不是结束活动时显示前一个片段.有没有办法做到这一点?谢谢塞巴斯蒂安