0
장치 화면의 크기에 따라 레이아웃을 만들고 싶습니다. 이건 내 MainActivity입니다.안드로이드에서 프로그래밍 방식으로 레이아웃의 크기를 설정
public class LoginActivity extends Activity {
int width_device;
int height_device;
LinearLayout layout_login_content;
LinearLayout.LayoutParams param;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Get screen size
width_device = Utility.getDeviceWidth(this);
height_device = Utility.getDeviceHeight(this);
// Get widget from layout
layout_login_content = (LinearLayout) findViewById(R.id.layout_login_content);
// Set up layout size
param = (LinearLayout.LayoutParams) layout_login_content
.getLayoutParams();
param.width = width_device * 60/100;
param.height = height_device * 60/100;
layout_login_content.setLayoutParams(param);
}
화면 크기를 얻는 방법에 대해 걱정할 필요가 없습니다. 나는 그것을했고 그것은 효과가 있었다.
이 내 main_fragment.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_login_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
tools:context="login.LoginActivity" >
</LinearLayout>
입니다 그리고 이것은 내가 여기에 무슨 일이 잘 모릅니다 오류 메시지
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
입니다. 나는 LinearLayout.LayoutParams
을 선언하고, LinearLayout
을 xml로 사용합니다. 하지만 왜 제대로 캐스팅 할 수 없습니까?
영어로 죄송합니다. 나는 당신에게 정말 고마워요 모두가 내가 :(무슨 뜻인지 희망 당신의 LinearLayout 일부 FrameLayout이의 PARAMS을 상속처럼
의미가 있습니다! 대단히 감사합니다!^_ ^ –