![](/img/trans.png)
[英]Why does the SeekBar not move when sound is played via MediaController (Android)?
[英]Android: Why does calling viewToFront() on a SeekBar not bring it to the top of the UI?
我正在嘗試使隱藏的SeekBar
(最初具有visibility = "gone"
)可見並顯示在覆蓋整個屏幕的黑色背景 LinearLayout 之上。 但是,當我運行我的代碼時,我只看到全屏LinearLayout
並且沒有看到位於LinearLayout
之上的SeekBar
:
下面是我的代碼:
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
</LinearLayout>
<SeekBar
android:id="@+id/seekbar"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:padding="0dp"
android:max="100"
android:progressDrawable="@android:color/transparent"/>
</LinearLayout>
MainActivity.java :
package com.example.changingimageviewwidth;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Make the image preview box visible
SeekBar seekbar = findViewById(R.id.seekbar);
seekbar.setVisibility(View.VISIBLE);
seekbar.bringToFront();
// Place the image preview box at a specified location
seekbar.setX(150);
seekbar.setY(150);
seekbar.setVisibility(View.VISIBLE);
seekbar.bringToFront();
// Place the image preview box at a specified location
seekbar.setX(150);
seekbar.setY(150);
}
}
這不能回答你的問題,但它可能會解決問題。 您可以使用ConstraintLayout
來 position SeekBar
。 它是一個扁平的層次結構,因此您可以將視圖堆疊在一起,然后您可以使用visibility
來隱藏/顯示它,而不是將其移動到位,它總是在那里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.