2017-12-22 16 views
-1

일부 서적에 따라 다음과 같은 설정이 있습니다. 그러나 앱이로드 될 때 진행률 막대가 표시되지 않습니다.시작시 진행 표시 줄이 표시되지 않습니다.

MainActivity.java

public class MainActivity extends AppCompatActivity implements View.OnClickListener { 

private EditText et; 
private ImageView iv; 
private ProgressBar pb; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button b = (Button)findViewById(R.id.button); 
    et = (EditText) findViewById(R.id.edittext); 
    b.setOnClickListener(this); 

    iv = (ImageView)findViewById(R.id.image); 
    pb = (ProgressBar)findViewById(R.id.progressbar); 
    pb.setVisibility(View.VISIBLE); 

} 

@Override 
public void onClick(View v){ 
    switch(v.getId()){ 
     case R.id.button: 
      //String input = et.getText().toString(); 
      //Toast.makeText(MainActivity.this, input,Toast.LENGTH_SHORT).show(); //** 
      //pb.setVisibility(View.VISIBLE); 
      break; 
     default: 
      break; 
    } 
} 

내가이 링크를 참조

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/text_view" 
    android:text="This is a text" 
    android:gravity="center" 
    android:textSize="24sp" 
    android:textColor="#00ff00" 
    /> 
<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="button" 
    android:textAllCaps="false" 
    android:id="@+id/button" 
    /> 

<EditText 
    android:id="@+id/edittext" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="Type sth here :)" 
    android:maxLines="2" 

    /> 

<ImageView 
    android:id="@+id/image" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/rose" 
    /> 

<ProgressBar 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/progressbar" 
    android:indeterminate="true" 
    android:layout_centerInParent="true" 
    /> 
</LinearLayout> 

내 activity_main.xml : ... 바는 간단하지 않습니다 내 경우에는 작동하지 않습니다 아직 Android progressBar not showing을하지만, 표시 ...

+0

이상한. xml 파일의 끝에 ""여야합니다, 나는 위에 추가하려고했지만 어떻게 든 나타나지 않습니다. –

+0

아 ... 왜 아래로 투표 르 ?? 그래서 낙심 ... 같은 종류에서 그것을 차별화 할만큼 고유 한 만큼이 질문에 도움이 생각 ... StackOverflow 정말 downvoting 사람들이 downvote 때, 이유와 같은 더 엄격한 제어해야한다 .. –

답변

1

루트 레이아웃은 LinearLayout입니다. android:layout_centerInParent은 Linearlayout의 자식에 대한 속성이 아닙니다. 따라서 'ProgressBar'를 가운데에 표시하려면 상대 레이아웃을 부모로 사용하는 것이 좋습니다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/text_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="This is a text" 
      android:textColor="#00ff00" 
      android:textSize="24sp" /> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="button" 
      android:textAllCaps="false" /> 

     <EditText 
      android:id="@+id/edittext" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Type sth here :)" 
      android:maxLines="2" 

      /> 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/rose" /> 

    </LinearLayout> 

    <ProgressBar 
     android:id="@+id/progressbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:indeterminate="true" /> 
</RelativeLayout> 
+0

그것이 작동! 대단히 감사합니다! "android : layout_centerInParent"를 사용하지 않을 때는 작동하지 않더라도. 그러나이 솔루션은 효과가 있으며이를 준수하는 것이 현명합니다. 큰 감사합니다 @ ADM, 당신은 내 두통을 해결! –

0

개발자 옵션에서 애니메이션을 해제 할 수 있습니다. 테스트 프로젝트에서 레이아웃 파일을 사용합니다. 진행률 표시 줄이 나타나고 정상적으로 작동합니다. 애니메이션을 해제하면 ProgressBar가 보이지 않습니다.

+0

삼성 휴대 전화에서 모든 애니메이션 관련 기능을 켰지 만 제대로 작동하지 않았습니다. 아니면 안드로이드 스튜디오에서 켜야하는 애니메이션 기능이 있다는 뜻입니까? –