2017-09-05 3 views
-1

기본 활동과 주 활동이 있지만 주 활동에서 weightsum을 적용했지만 올바르게 작동하지 않습니다. 다음은 예상 전류 출력 enter image description hereLinearLayout, weightSum이 제대로 작동하지 않습니다.

MainActivity.java

public class MainActivity extends BaseActivity { 
    LinearLayout dynamicContent,bottonNavBar; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     dynamicContent = (LinearLayout) findViewById(R.id.dynamicContent); 
     bottonNavBar= (LinearLayout) findViewById(R.id.bottonNavBar); 
     View wizard = getLayoutInflater().inflate(R.layout.activity_main, null); 
     dynamicContent.addView(wizard); 
} 
} 

에게 Mainactivity.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    android:weightSum="2" 
    android:layout_height="match_parent" 
    android:background="#F5F5F5" 
    tools:context="com.creativeframe.arun.pro.MainActivity"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@drawable/cbseschool" 
     android:orientation="vertical"> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@drawable/college" 
     android:orientation="vertical"> 

     </LinearLayout> 

</LinearLayout> 

BaseActivity.java

public class BaseActivity extends AppCompatActivity { 


    RadioGroup radioGroup1; 
    RadioButton home,deals,account,settings; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_base); 
     home = (RadioButton)findViewById(R.id.homebtn); 
     deals = (RadioButton)findViewById(R.id.dealsbtn); 
     account = (RadioButton)findViewById(R.id.accountbtn); 
     settings = (RadioButton)findViewById(R.id.settingbtn); 

     home.setCompoundDrawablesWithIntrinsicBounds(0,R.mipmap.ic_home_white_24dp, 0,0); 
     deals.setCompoundDrawablesWithIntrinsicBounds(0,R.mipmap.ic_navigation_white_24dp, 0,0); 
     account.setCompoundDrawablesWithIntrinsicBounds(0,R.mipmap.ic_about, 0,0); 
     settings.setCompoundDrawablesWithIntrinsicBounds(0,R.mipmap.ic_call_white_24dp, 0,0); 

     radioGroup1=(RadioGroup)findViewById(R.id.radioGroup1); 
     radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() 
     { 
      @Override 
      public void onCheckedChanged(RadioGroup group, int checkedId) 
      { 
       switch (checkedId) 
       { 
        case R.id.homebtn: 
         home.setTextColor(Color.parseColor("#FF4081")); 
         startActivity(new Intent(getBaseContext(),MainActivity.class)); 
         finish(); 
         overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); 
         break; 
        case R.id.dealsbtn: 
         deals.setTextColor(Color.parseColor("#FF4081")); 
         startActivity(new Intent(getBaseContext(), location.class)); 
         finish(); 
         overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); 

         break; 
        case R.id.settingbtn: 
         settings.setTextColor(Color.parseColor("#FF4081")); 
         startActivity(new Intent(getBaseContext(), contact.class)); 
         finish(); 
         overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); 
         break; 
        case R.id.accountbtn: 
         account.setTextColor(Color.parseColor("#FF4081")); 
         startActivity(new Intent(getBaseContext(), about.class)); 
         finish(); 
         overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); 
         break; 
        default: 
         break; 
       } 
      } 
     }); 
    } 
} 
+0

'weightSum'는 ** 완전히 선택 사항입니다 **. 또한 가중치 크기 (단 하나! 폭 또는 높이 중에서 선택)는 ** 정확히 0dp **이어야합니다. 또한 중첩 레이아웃은 공연에 영향을줍니다. ** 부정적인 **. 누군가 숙제를 못하니? ;) –

+1

각 하위보기의 높이를 0dp – codeMagic

+0

으로 변경하십시오. 'BaseActivity'에서 펼친 레이아웃을 게시 할 수 있습니까? 나는 당신의 다른 XML이 올바르게 보이는 것처럼 문제가 거기에 있다고 생각한다. – codeMagic

답변

1

당신의 Mainactivity에서 다음 시도 .xml

자녀의 LinearLayout layout_height를 match_parent에서 0dp로 변경하십시오.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:orientation="vertical" 
android:weightSum="2" 
android:layout_height="match_parent" 
android:background="#F5F5F5" 
tools:context="com.creativeframe.arun.pro.MainActivity"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="@drawable/cbseschool" 
    android:orientation="vertical"> 

</LinearLayout> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="@drawable/college" 
    android:orientation="vertical"> 

    </LinearLayout> 

    </LinearLayout> 

MainActivity에서 레이아웃보기를 다음과 같이 설정하십시오. 수평 분할에 대한

public class MainActivity extends BaseActivity { 
LinearLayout dynamicContent,bottonNavBar; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    dynamicContent = (LinearLayout) findViewById(R.id.dynamicContent); 
    bottonNavBar= (LinearLayout) findViewById(R.id.bottonNavBar); 

} 
} 
+2

다른 사람들이 더 잘 배울 수 있도록 * 당신이 변경 한 것이 * 어떻게 * 문제를 해결할 것인지를 설명하는 것이 더 낫습니다. – codeMagic

+0

아니요 작동하지 않습니다 –

+0

수정 된 답변을 시도하십시오. –

1

사용

android:layout_width="0dp" 

및 수직 사용하기 위해

:

android:layout_height="0dp" 

예 :

 <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 
      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="fitXY" 
       android:src="@mipmap/ic_launcher"/> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 
      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="fitXY" 
       android:src="@mipmap/ic_launcher"/> 
     </LinearLayout> 
    </LinearLayout>