我在 RelativeLayout 上使用 scrollBy() 来尝试滚动到可见屏幕右侧的按钮,但我只看到空白屏幕。屏幕边框上的按钮被剪裁,并在滚动后(在任何方向)保持剪裁。
我已经在 relativelayout 参数上尝试了几乎所有 WRAP CONTENT 和 FILL PARENT 组合。
我还尝试在 setContentview() 中使用 LinearLayout,但它不起作用。
我需要视图水平滚动,并且应用程序设置为始终处于横向模式。
是否必须以某种方式重新绘制或刷新布局才能显示丢失的按钮?
我需要使用其他视图类型来实现这种功能吗?
感谢您的任何意见。
-内森
以下是从顶部到 onCreate() 末尾的所有代码:
package golfcaddy.tools;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class GolfScoreRel extends Activity implements OnClickListener {
// Settings file, preferences
public static final String PREFS_NAME = "golfscore";
public static final String PREFS_SCORES = "scores";
public static final String PREFS_BACKGROUND_IMAGE = "backimage";
SharedPreferences mSettings;
private int currentX = 0;
private int currentY = 0;
int numHoles = 0;
int numplayers = 0;
RelativeLayout r1;
LinearLayout lin;
public int mLastScoreEntered;
//manages unique ID's for all view inside Relative layouts
int viewCount = 1;
// int holeScoresFront[] = new int[9];
// int holeScoresFrontb[] = new int[9];
Button mLastClicked;
Button exitButton;
TextView pTotal1;
TextView pTotal2;
@Override
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// lin = new LinearLayout(this);
// lin.setOrientation(LinearLayout.VERTICAL);
/* not used yet....
GolfPlayer p1 = new GolfPlayer("P 1");
GolfPlayer p2 = new GolfPlayer("P 2");
GolfPlayer p3 = new GolfPlayer("P 3");
GolfPlayer p4 = new GolfPlayer("P 4");
*/
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
r1 = new RelativeLayout(this); // this layout will be set for contentview
r1.setLayoutParams(params);
numplayers = 4; //standard golf group
numHoles = 18; //standard golf round
r1.addView(createCard(numplayers,numHoles));
setContentView(r1);
} //end oncreate
这是我从某个地方借来的 r1.scrollBy() 代码:
Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
currentX = (int) event.getRawX();
currentY = (int) event.getRawY();
break;
}
case MotionEvent.ACTION_MOVE: {
int x2 = (int) event.getRawX();
int y2 = (int) event.getRawY();
r1.scrollBy(currentX - x2 , currentY - y2);
currentX = x2;
currentY = y2;
break;
}
case MotionEvent.ACTION_UP: {
break;
}
}
return true;
}
屏幕截图说明:我们应该会在右侧看到另外 8 个按钮。
最后一张照片显示了一张 5 人卡,其中 DEBUG 按钮被剪掉了。
Dang,作为一个新用户,我不允许发布图像。尝试在这里查看它们: http ://groups.yahoo.com/group/nateandroiddev/photos/album/776905892/pic/list?mode=tn&order=ordinal&start=1&dir=asc