1
두 개의 이미지보기를 보유하기 위해 맞춤 선형 레이아웃을 만들고 있습니다. 처음에는 레이아웃이 전혀 보이지 않는다고 생각했지만 레이아웃을 부풀려서 검정색으로 설정했습니다. 그런 다음 문제는 단순히 이미지가 아니라는 것을 이해합니다.맞춤 레이아웃 내의보기가 표시되지 않습니다.
이 :-) 사전에
덕분 클래스 :
public class LoginIcons extends LinearLayout {
private ImageView mImageViewLogo;
private ImageView mImageViewIcons;
private View mView;
boolean test = false;
public LoginIcons(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public LoginIcons(Context context) {
super(context);
init();
}
private void init() {
setOrientation(LinearLayout.VERTICAL);
mImageViewLogo = new ImageView(this.getContext());
mImageViewIcons = new ImageView(this.getContext());
mView = new View(getContext());
LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mImageViewLogo.setLayoutParams(params);
params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.topMargin = (int)LocalSettingsHelper.dpToPx(getContext(), 20);
mImageViewIcons.setLayoutParams(params);
params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.topMargin = (int)LocalSettingsHelper.dpToPx(getContext(), 10);
mView.setLayoutParams(params);
mImageViewLogo.setImageResource(R.drawable.splash_logo_placeholder);
mImageViewIcons.setImageResource(R.drawable.login_icons);
mImageViewIcons.setBackgroundColor(Color.BLACK);
mImageViewLogo.setBackgroundColor(Color.BLACK);
addView(mView);
addView(mImageViewLogo);
addView(mImageViewIcons);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
setViewsDimensions();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
}
private void setViewsDimensions() {
LinearLayout parent = (LinearLayout) mImageViewLogo.getParent();
int screenWidth = LocalSettingsHelper.getScreenWidth(getContext());
// 0.375 percent
int imgDim = (int) ((double) screenWidth * 0.32);
int iconsWidth = (int) ((double) screenWidth * 0.5);
LinearLayout.LayoutParams params = (LayoutParams) mImageViewLogo
.getLayoutParams();
params.width = imgDim;
params.height = imgDim;
mImageViewLogo.setLayoutParams(params);
params = (LayoutParams) mImageViewIcons.getLayoutParams();
params.width = iconsWidth;
mImageViewIcons.setLayoutParams(params);
}
}
그리고 이것은 XML입니다 :
보기 객체가 match_parent처럼 행동하고 있었다 것 같다<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/HeaderBackground"
android:orientation="vertical" >
<Button
android:id="@+id/button_ok"
style="@style/LoginOkButtonStyle"
android:background="@drawable/blue_button_background_selector"
android:text="@string/ok" />
<com.example.me.entities.views.LoginIcons
android:id="@+id/loginIcons"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</com.example.me.entities.views.LoginIcons>
</LinearLayout>
'imgDim'과'iconsWidth'의 값이 무엇인지 테스트 해 본다면 명백한 의문이 생길 것입니다. – Luksprog
예, 값이 정확합니다. – Tsikon