我是韩国人,下图是韩语。嗯..这个事实并不重要。我尝试在线性布局中添加自定义视图,并且它成功地处于线性布局中。但它不在中心水平线上。我确实将线性布局中心的重力设置为水平。但这行不通。我猜问题的原因是布局参数。自定义视图类没有问题,调试时也没有出现任何错误。我该怎么办??
XML 代码中的活动:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="NestedScrolling">
<LinearLayout
android:id="@+id/select_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<!--Here is-->
</LinearLayout>
</ScrollView>
添加视图方法:
ThemeManager mTheme;
Button selectTopBoardButton;
LinearLayout selectBody;
ThemeView c0001;
ThemeView c0002;
ThemeView c0003;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select);
gestureDetectorCompat = new GestureDetectorCompat(this, new MainActivityGoer());
NetworkDetector networkDetector = new NetworkDetector(this);
if (!networkDetector.isConnected()) {
Toast.makeText(SelectActivity.this, "네트워크에 접속할 수 없습니다.", Toast.LENGTH_SHORT).show();
}
selectTopBoardButton = (Button) findViewById(R.id.select_top_board_button);
selectBody = (LinearLayout) findViewById(R.id.select_body);
mTheme = new ThemeManager(this);
c0001 = mTheme.getThemeView("c0001");
c0002 = mTheme.getThemeView("c0002");
c0003 = mTheme.getThemeView("c0003");
selectTopBoardButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = getResources().getString(R.string.main_request_btn06_url);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
selectBody.addView(c0001);
}